|
|
Re: add child in parent constructor [message #897447 is a reply to message #897331] |
Tue, 24 July 2012 07:48 |
user Kyle Messages: 19 Registered: April 2012 |
Junior Member |
|
|
For example, if I use wizard "Application Window" in Swing designer:
I have the code:
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(21, 11, 373, 226);
frame.getContentPane().add(panel);
panel.setLayout(null);
JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(124, 107, 89, 23);
panel.add(btnNewButton);
}
But if I want to customize my panel and I add child in constructor like:
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
MyPanel panel = new MyPanel();
panel.setBounds(10, 11, 270, 194);
frame.getContentPane().add(panel);
panel.setLayout(null);
}
And MyPanel constructor (who extends JPanel):
public MyPanel(){
super();
JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(89, 60, 89, 23);
add(btnNewButton);
}
In designer my button does not appear on tree and I can not select it!
Thanks to your answer
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02283 seconds