Re: [JPanel child of JPanel]how to get a rectangle object with the
dimensions of the JPanel object
Daniel Moyne wrote:
I have built a childJPanel child of another mainJPanel and I cannot get its
dimensions ; I tried :
Rectangle ee=childJPanel.getBounds();
childJPanel.getX();
childJPanel.getHeight();
but all the time I get 0 !
For the time being the layout of my mainJPanel is Absolute where I have
positioned my childJPanel with xpos, ypos, height and width but I do not
think that here it has no direct impact as the methods listed above shoud
work for any layouts ?
Thanks.
Can you see this childJPanel? My best guess is that it's size is zero.
import java.awt.*;
import java.awt.event.*;
public class test8 extends Frame {
public test8() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dispose();
}
});
Panel parent = new Panel(null);
parent.setBackground(Color.BLUE);
add(parent);
Panel child = new Panel();
child.setBackground(Color.YELLOW);
child.setBounds(50,50,50,50);
parent.add(child);
setSize(320,240);
setVisible(true);
System.out.println(child.getBounds());
}
public static void main(String[] args) {
new test8();
}
}
C:\Documents and Settings\Knute Johnson>java test8
java.awt.Rectangle[x=50,y=50,width=50,height=50]
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access