Problems with JLabels in a special window ...

Discussion in 'Java' started by Arnaud, Jan 14, 2004.

  1. Arnaud

    Arnaud Guest

    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();
    }

    }
     
    Arnaud, Jan 14, 2004
    #1
    1. Advertising

  2. Arnaud

    hiwa Guest

    Arnaud <> wrote in message news:<40059ff5$0$6982$-internet.fr>...

    setOpaque(true)
     
    hiwa, Jan 15, 2004
    #2
    1. Advertising

  3. "hiwa" <> wrote in message
    news:...
    | Arnaud <> wrote in message
    news:<40059ff5$0$6982$-internet.fr>...
    |
    | 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.. ]

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
     
    Andrew Thompson, Jan 15, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rob bell
    Replies:
    1
    Views:
    434
    Chris Smith
    Sep 24, 2003
  2. Pestry

    grid of JLabels

    Pestry, Jan 4, 2006, in forum: Java
    Replies:
    2
    Views:
    483
    Tris Orendorff
    Jan 6, 2006
  3. Jason Cavett

    JLabels Are Big

    Jason Cavett, Mar 4, 2008, in forum: Java
    Replies:
    9
    Views:
    504
    Mark Space
    Mar 6, 2008
  4. KDawg44

    Array of JLabels

    KDawg44, Apr 2, 2008, in forum: Java
    Replies:
    7
    Views:
    2,631
  5. albert kao
    Replies:
    6
    Views:
    1,391
    Knute Johnson
    Apr 26, 2011
Loading...

Share This Page