|
-
September 20th, 2011, 11:58 AM
#1
Inserting pre programmed UI elements
Hi everyone, its my first time in this forum!
i am kind of new to java programming and iam about to start a project, a java web start application
for now, i need to know how can I develop a bar menu, a status bar, or another set of elements that are going to be common for many jframes
the thing is that I need to programm them one time, and insert in all the frames that are required, dont know if I explain myself
excuse my mistakes, i am from venezuela and my english is not that good
Thanks in advance and I will be here everyday from now!
Something missing: I am working with netbeans ide 7.0.1
-
September 20th, 2011, 01:03 PM
#2
Re: Inserting pre programmed UI elements
You can't share the same instance of GUI components with different panels/frames so you have create a new instance for each panel/frame you want to add them to. To do this you can have a factory to create the components you want multiple instances of. You then call the factory's methods each time you want a new component with your predetermined values (or optionally pass in values to configure the object). For example in it's simplest form a method might be something like:
Code:
public static JMenuBar createMyMenuBar()
{
JMenuBar myMenuBar = new JMenuBar();
JMenu myMenu1 = new JMenu("My Menu 1");
myMenuBar.add(myMenu1);
...
return myMenuBar;
}
And you would use it like this:
Code:
JFrame myFrame = new JFrame();
mtFrame.setJMenuBar(MyGuiFactoryClass.createMyMenuBar());
For help on creating/using menus read the Java tutorial
-
September 20th, 2011, 05:46 PM
#3
Re: Inserting pre programmed UI elements
The other questions:
how to put names on the menu items
how do you add listeners to respond to the menu events?
Perhaps the create method should take an array of names for the items and a listener reference.
Norm
-
September 20th, 2011, 07:42 PM
#4
Re: Inserting pre programmed UI elements
wow thats beyond my narrow knowledge, i will try something and come back to the forum! thanks for helping
-
September 20th, 2011, 07:46 PM
#5
Re: Inserting pre programmed UI elements
In pseudo code:
Code:
public static JMenuBar createMyMenuBar(String[] names, Listener lstnr)
{
JMenuBar myMenuBar = new JMenuBar();
for(String aName : names) {
JMenu myMenu1 = new JMenu(aName);
myMenu1.addListener(lstnr);
myMenuBar.add(myMenu1);
}
...
return myMenuBar;
}
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|