Re: [Swing] Controlling depth of multiple JWindows.

From: ak (spam_at_imagero.com)
Date: 12/30/03


Date: Tue, 30 Dec 2003 03:51:28 +0100


> Thanks for your response, but can you please elaborate? Why should I
> work only with JWindows?
because only with JWindow and JDialog you can have such hierarchie, but
JDialog always have title bar.
if you need to have title bar and border, you can implement it.

This is not really perfect solution (but I know only this one) - look at
code below - if you click at level3 then level2 is over level3b (tested only
with ms-windows)

public class JWinTest {

 public static void main(String[] args) {
  JWindow owner = new JWindow();
  JWindow level1 = new JWindow(owner);
  JWindow level2 = new JWindow(level1);
  JWindow level3 = new JWindow(level2);
  JWindow level2b = new JWindow(level1);
  JWindow level3b = new JWindow(level2b);

  new DragHandler(owner);
  new DragHandler(level1);
  new DragHandler(level2);
  new DragHandler(level2b);
  new DragHandler(level3);
  new DragHandler(level3b);

  owner.setBounds(200, 200, 400, 400);
  level1.setBounds(300, 300, 300, 300);
  level2.setBounds(200, 200, 200, 200);
  level2b.setBounds(200, 200, 200, 200);
  level3.setBounds(200, 200, 100, 100);
  level3b.setBounds(300, 300, 100, 100);

  level1.getContentPane().setBackground(Color.green);
  level2.getContentPane().setBackground(Color.green.darker());
  level3.getContentPane().setBackground(Color.green.darker().darker());
  level2b.getContentPane().setBackground(Color.blue);
  level3b.getContentPane().setBackground(Color.blue.darker());

  owner.setVisible(true);
  level1.setVisible(true);
  level2.setVisible(true);
  level2b.setVisible(true);
  level3.setVisible(true);
  level3b.setVisible(true);
 }

 static class DragHandler extends MouseInputAdapter {

  int x0, y0, x, y;
  Window window;
  Rectangle rw = new Rectangle();

  public DragHandler(Window window) {
   this.window = window;
   window.addMouseListener(this);
   window.addMouseMotionListener(this);
  }

  public void mousePressed(MouseEvent e) {
   x = e.getX();
   y = e.getY();
   Point p = new Point(x, y);
   SwingUtilities.convertPointToScreen(p, e.getComponent());
   x = p.x;
   y = p.y;

   x0 = window.getX();
   y0 = window.getY();
  }

  public void mouseReleased(MouseEvent e) {
  }

  public void mouseDragged(MouseEvent e) {
   Point p = e.getPoint();
   SwingUtilities.convertPointToScreen(p, e.getComponent());
   int dx = x - p.x;
   int dy = y - p.y;
   rw = window.getBounds(rw);
   rw.x = x0 - dx;
   rw.y = y0 - dy;

   window.setLocation(rw.x, rw.y);
  }
 }
}
____________

http://reader.imagero.com the best java image reader.



Relevant Pages

  • Re: how to self-destruct an object in Java?
    ... onto the background of subclasses of the AWT components Frame (JFrame), dialog (JDialog) and Window (JWindow), all of which are ...
    (comp.lang.java.help)
  • Re: JDialog not appearing for JWindow under Java 1.5
    ... I am using a JWindow for the main window of an application for its ... If the program compiles and ... If the JWindow is changed to JFrame, ... public void actionPerformed{ ...
    (comp.lang.java.gui)
  • Re: how to get KeyPressed event inside JWindow
    ... A JWindow class is my main class (w/o all the title, min, max controls, ... But when I add a KeyListener, ... JLabel lbl = new JLabel; ... public void keyPressed ...
    (comp.lang.java.programmer)
  • Re: JPopupMenu bug
    ... > public void windowDeactivated ... I just noticed that the above works with JFrame and JDialog, ... but not with JWindow. ...
    (comp.lang.java.gui)
  • Re: Disable window animation
    ... I would like that window ... I have tryed using JWindow instead (so there is no ... keyboard focus. ... How can I disable animation? ...
    (comp.lang.java.programmer)