views:

352

answers:

2

i am particularly using netbeans gui editor and i am new to gui

i have a jframe created and I added jtabbedpanel.

inside the jtabbedpanel i have 2 panels that i call standard and compact

i have set standardPanel = new ImagePanel(); which ImagePanel.java is located on different java file

how am I suppose to put a panel on different file for reusability ?

i obviously dont want all the codes in a single file.

is this the right way to design a gui ?

thanks

+1  A: 

You should create your own class, something like "CustomPanel" that extends from JPanel. You put that class in its own file, and everything that goes on the JPanel should be a part of that class.

Then, instead of adding a JPanel to the tabbed panel, you create an instance of CustomPanel and add it to the tabbed panel.

Marcus Adams
yes that is what i did but the problem is now i want to include that jpanel to my jframe class my jframe has standardPanel which I want to initialize standardPanel as ImagePanel defined in other class.let me know if my question is confusing?
stdnoit
@stdnoit, yes, you've lost me. Please provide sample code, or at least pseudo code of what you have, and what you expect.
Marcus Adams
please check my reply as answer on the above. thanks. its too long to be here. thanks Marcus
stdnoit
A: 

thanks.now it is partly working

so i hv MainWindow extends Jframe has following private javax.swing.JPanel standardPanel = new ImagePanel(); ImagePanel is defined in other file, of course.

the problem before is that the imagePanel() does not display anything

the sample code that i got has overriden the paint method so it allow something to display. at least at this point i know a jframe can call jpanel & jpanel handles "its own" display

now the problem is where i should define my data model as there are many jpanels in my jframe and they all share the same model. i wonder if this is the right way of creating gui. i am new.

too many words to reply the comment so i put it as answer. sorry.

stdnoit
Please post the code. I don't understand your terminology. I don't understand the question "where I should define my data model". Please edit your question rather than posting in an answer. Thanks.
Marcus Adams