JFrame transparente?!

Como eu faço para colocar um JFrame transparente?

Tem jeito?

[quote=arm.jr]Como eu faço para colocar um JFrame transparente?

Tem jeito?
[/quote]

Cara , pior que tem …achei um cara aqui que fez …

Dá uma sacada lá …não testei …mas tem um caps lá no site.
[color=red]Janela Tranparente[/color]
:arrow: Link Direto do arquivo

Transparent Window Class - Default branch

Depois coloca aqui se funcionou legal…

T+, espero ter ajudado !

Ou será que vc não teria esse código ai tentei baixar mais o arquivo esta corrompido…

Aguardo a resposta Obrigado.

[quote=rodrigo.java]Ou será que vc não teria esse código ai tentei baixar mais o arquivo esta corrompido…

Aguardo a resposta Obrigado.[/quote]

Segue abaixo o código do JFrame Transparente

/*
 * JTransFrame.java
 *
 * Created on August 21, 2004, 10:27 PM
 * A borderless, backgroundless Swing root pane.
 * Known issue -- the background change detector can't always intercept requests in the
 * underlying UI to update the background when windows move upwards past the JTransFrame
 * in the z-order. This sometimes leaves artifacts in the background buffer.
 *
 * This code was revised and edited by Josh Turner, Thank you very
 * much for your contribution.
 *
 * Original code:
 * James Neufeld
 * neufeld@cs.ualberta.ca
 * www.ugweb.cs.ualberta.ca/~neufeld/transframe.tar.gz
 * 
 */

package com.readytoware.ui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;

public class JTransFrame extends JFrame {
    
    Robot robot;
    BufferedImage bi = null;
    int redM, greenM, blueM;
    boolean trans;
    boolean dirty = false;
    DirtFlagger dirtFlagger = new DirtFlagger();
    Thread thread;
    PrimeRun p;
    
    /**
     * This constructer takes in the alpha blending
     * Values for transparent windows.
     *
     * @param int r
     * @param int g
     * @param int b
     */
    public JTransFrame(int r, int g, int b) {
        setUndecorated(true);
        setContentPane(new TransRootPane());
        trans = false;
        redM = r;
        greenM = g;
        blueM = b;
    }
    
    public JTransFrame() {
        this(0,0,0);
    }
    
    /**
     * This method is true if the window is in transparent mode.
     *
     * @return boolean trans
     */
    
    public boolean isTransparent() {
        return trans;
    }
    /**
     * This method sets the window in or out of transparent mode
     *
     * @param boolean b
     */
    public void setTransparent(boolean b) {
        trans = b;
        maketrans();
    }
    
    /**
     * Initializes all the components for the frame.
     * Should always be called when a new instance is
     * created.
     */
    public void initTransComponents() throws Exception {
        //label = new JLabel();
        //getContentPane().setLayout(null);
        //getContentPane().add(label);
        robot = new Robot();
        
        p = new PrimeRun(this);
        thread = new Thread(p);
        thread.start();
    }
    /**
     * This method stops the resize/move listener threads.
     */
    public void stopThreads() {
        p.running = false;
    }
    /**
     * This method makes the window transparent when called.
     *
     */
    public void maketrans() {
        
        if (trans) {
            removeWindowListener(dirtFlagger);
            bi = robot.createScreenCapture(new Rectangle(getLocation().x,
            getLocation().y,
            getSize().width,
            getSize().height));
            
            for (int i=0; i < bi.getHeight(); i++) {
                for (int j=0; j < bi.getWidth(); j++) {
                    
                    int rgba = bi.getRGB(j, i);
                    int red = (rgba >> 16) & 0xff;
                    int green = (rgba >> 8) & 0xff;
                    int blue = rgba & 0xff;
                    int alpha = (rgba >> 24) & 0xff;
                    
                    if (red < redM)
                        red = 0;
                    else
                        red -= redM;
                    if (green < greenM)
                        green = 0;
                    else
                        green -= greenM;
                    if (blue < blueM)
                        blue = 0;
                    else
                        blue -= blueM;
                    
                    rgba = (alpha << 24) | (red << 16) | (green << 8) | blue;
                    bi.setRGB(j, i, rgba);
                }
                
            }
            
           
            getContentPane().repaint();
            getRootPane().repaint();
            setVisible(true);
            dirty = false;
            addWindowListener(dirtFlagger);
        } else {
            
            validate();
            repaint();
        }
    }
    
    class DirtFlagger implements java.awt.event.WindowListener
    {
        
        public void windowStateChanged(WindowEvent e) {
        }
        
        public void windowActivated(WindowEvent e) {
            dirty = true;
        }
        
        public void windowClosed(WindowEvent e) {
        }
        
        public void windowClosing(WindowEvent e) {
        }
        
        public void windowDeactivated(WindowEvent e) {
            //dirty = true;
        }
        
        public void windowDeiconified(WindowEvent e) {
            dirty = true;
        }
        
        public void windowIconified(WindowEvent e) {
        }
        
        public void windowOpened(WindowEvent e) {
            dirty = true;
        }
        
    }
    
    
    class TransRootPane extends javax.swing.JComponent {
        public void paint(java.awt.Graphics g) {
            if(trans) {
                if(bi != null) {
                    g.drawImage(bi, 0, 0, null);
                }
            }
            super.paint(g);
        }
        
    }
    
    /**
     * This Class is basically a resize/move listener.
     *
     * @author James Neufeld
     *
     */
    
    class PrimeRun implements Runnable {
        JTransFrame tf;
        int x, y, w, h;
        public boolean running = true;
        
        /**
         * The constructer takes in the frame to listen too.
         *
         */
        PrimeRun(JTransFrame t) {
            
            tf = t;
            y = tf.getLocation().y;
            x = tf.getLocation().x;
            h = tf.getSize().height;
            w = tf.getSize().width;
        }
        
        /**
         * This method tells the class how to listen to resize/move
         * events.  It is automatically called when it is used in a
         * thread.
         */
        public void run() {
            
            while (running) {
                while((x == tf.getLocation().x)
                && (y == tf.getLocation().y)
                && (w == tf.getSize().width)
                && (h == tf.getSize().height)
                && (!dirty)
                && (running)) { }
                
                x = tf.getLocation().x;
                y = tf.getLocation().y;
                h = tf.getSize().height;
                w = tf.getSize().width;
                if (tf.isTransparent()) {
                    tf.setVisible(false);
                    tf.maketrans();
                }
            }
        }
    }
}

[quote]
TransFrame.java

to use:

class someFrame extends TransFrame {

    public someFrame() {

            super(50, 50, 50);

            try {
                    super.initComponents();         
            }
            catch (Exception e) { /* Handle it */}

    }

}

This software is free for non-commercial use, of course.
go ahead and edit it to suit your needs.

problems:

For large windows this can be quite slow!
blame the JVM :slight_smile:

James Neufeld
neufeld@cs.ualberta.ca[/quote]

Um abraço.

eu uso

mas so vai funcionar com java 6 update 10 em diante

Como é que se usa essa classe?
Eu fiz assim:

  public class NewClass {

    public static void main(String args[]){
        JTransFrame frameTrans = new JTransFrame(15, 5, 4);
        frameTrans.setSize(500, 500);
        frameTrans.setLocationRelativeTo(null);
        frameTrans.setVisible(true);
        frameTrans.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

e apareceu uma tela cinza sem barra de titulo nem nada.
Eu fiz certo?