Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » add child in parent constructor
add child in parent constructor [message #897331] Mon, 23 July 2012 15:41 Go to next message
user Kyle is currently offline user KyleFriend
Messages: 19
Registered: April 2012
Junior Member
Hi,

I have a problem, I want to add child in parent constructor but it don't work!

For example (in swing),

In my main I have,
MyPanel panel = new MyPanel();


And MyPanel contains some composite like,
public MyPanel() {
   textField = new JTextField();
   add(textField);
   textField.setColumns(10);
}


If child is not in constructor (so just after line, MyPanel panel = new MyPanel(); for example) it works but not if I put child in my contructor!

Thanks to your help
Re: add child in parent constructor [message #897423 is a reply to message #897331] Tue, 24 July 2012 05:09 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
Works fine for me.

I'm not sure what you mean by "it don't work". Please be specific.
Re: add child in parent constructor [message #897447 is a reply to message #897331] Tue, 24 July 2012 07:48 Go to previous messageGo to next message
user Kyle is currently offline user KyleFriend
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 Wink
Re: add child in parent constructor [message #898551 is a reply to message #897447] Thu, 26 July 2012 14:59 Go to previous messageGo to next message
user Kyle is currently offline user KyleFriend
Messages: 19
Registered: April 2012
Junior Member
If it's not implemented in original toolkits, have you any idea on how can I proced for my toolkit?

For example, how can I proced to parse and create JavaInfo in all my project? Not only in main page..

[Updated on: Thu, 26 July 2012 15:06]

Report message to a moderator

Re: add child in parent constructor [message #898642 is a reply to message #897447] Fri, 27 July 2012 01:35 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
user Kyle wrote on Tue, 24 July 2012 03:48
In designer my button does not appear on tree and I can not select it!

Everything is working as expected. That button should not appear in the tree of the App Window as it is a component private to MyPanel (doing so would require breaking encapsulation which is not allowed). It should only show up in the tree of MyPanel.
Re: add child in parent constructor [message #899029 is a reply to message #898642] Mon, 30 July 2012 09:18 Go to previous message
user Kyle is currently offline user KyleFriend
Messages: 19
Registered: April 2012
Junior Member
Ok, thanks to your answer Wink
Previous Topic:How to switch to Design View
Next Topic:Generic Panel/Dialog with Actions will not render GUI
Goto Forum:
  


Current Time: Fri Apr 19 11:58:20 GMT 2024

Powered by FUDForum. Page generated in 0.02283 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top