Problems with JLabels in a special window ...

A

Arnaud

hi !

I've created a special window (transparent), but I've got problem : when I
add JLabels to it, they don't appear in the window !

Here's my code (yhe code for the transparent window isn't optimised yet,
that's just a short version, not too long, to understand the basic
mechanism) :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class TransparentWindow extends JWindow implements
MouseMotionListener, FocusListener {

JPanel contentPane;
JLabel label1 = new JLabel("Hello !");

Image img,tim;
Graphics tig;
Point mp;
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();


public TransparentWindow() {

setBounds((int)(d.getWidth()-475)/2,0,475,100);
capture();

contentPane = (JPanel) getContentPane();
contentPane.setLayout(new FlowLayout(10,10,FlowLayout.CENTER));
contentPane.add(label1);

addMouseMotionListener(this);
addFocusListener(this);

setVisible(true);
}


public void focusGained(FocusEvent fe)
{
Point p = getLocation();
setLocation(11111,0);
capture();
setLocation(p);
}

public void focusLost(FocusEvent fe)
{
}

public void capture()
{
try {
Robot r = new Robot();
Rectangle rect = new Rectangle(0,0,d.width,d.height);
img = r.createScreenCapture(rect);
}
catch(AWTException awe) {
System.out.println("robot excepton occurred");
}
}

public void mouseDragged(MouseEvent m)
{
Point p = m.getPoint();
int x = getX()+p.x-mp.x;
int y = getY()+p.y-mp.y;
setLocation(x,y);
Graphics g = getGraphics();
paint(g);
}

public void mouseMoved(MouseEvent m)
{
mp = m.getPoint();
}

public void paint(Graphics g)
{
if (tim == null)
{
tim = createImage(getWidth(),getHeight());
tig = tim.getGraphics();
}
tig.drawImage(img,0,0,getWidth(),getHeight(),
getX(),getY(),getX()+getWidth(),getY()+getHeight(),null);
tig.setColor(new Color(0,0,0,128));
tig.fillRoundRect(0,0,getWidth(),getHeight(),100,120);
g.drawImage(tim,0,0,null);
}

public void cupdate(Graphics g)
{
this.paint(g);
}


public static void main (String[] args)
{
new TransparentWindow();
}

}
 
A

Andrew Thompson

|
| setOpaque(true)

Unfortunately that does not solve the problem, hiwa
(I was playing with the OP's code, and tried it)

[ Note he is talking _transparent_ windows here.. ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,589
Members
45,100
Latest member
MelodeeFaj
Top