Re: [Swing] Controlling depth of multiple JWindows.
From: ak (spam_at_imagero.com)
Date: 12/30/03
- Next message: Andrew Thompson: "Re: How to assign a string buffer to a JEditorPane"
- Previous message: Andrew Thompson: "Re: Reusing JFileChooser instances"
- In reply to: Andrew Jackman: "Re: [Swing] Controlling depth of multiple JWindows."
- Next in thread: Andrew Jackman: "Re: [Swing] Controlling depth of multiple JWindows."
- Reply: Andrew Jackman: "Re: [Swing] Controlling depth of multiple JWindows."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Andrew Thompson: "Re: How to assign a string buffer to a JEditorPane"
- Previous message: Andrew Thompson: "Re: Reusing JFileChooser instances"
- In reply to: Andrew Jackman: "Re: [Swing] Controlling depth of multiple JWindows."
- Next in thread: Andrew Jackman: "Re: [Swing] Controlling depth of multiple JWindows."
- Reply: Andrew Jackman: "Re: [Swing] Controlling depth of multiple JWindows."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|