Article View: borland.public.jbuilder.java.language
Article #16786Re: adding components with a function
From: Jeff Rafter
Date: Tue, 19 Jan 1999 00:00
Date: Tue, 19 Jan 1999 00:00
34 lines
1700 bytes
1700 bytes
Daniel R. J. Lind
You can't create a new variable using the value of another variable
> javax.swing.JPanel tabName = new javax.swing.JPanel();
<<---------------------
A better way to do this is to keep an array of JPanels. You can acces these
by number later. The above code (if compiled) would change the tabName
variable from a String Object to a javax.swing.JPanel object.
void jButton1_actionPerformed(ActionEvent e) {
// get count
int z = jSlider1.getValue();
// create an array of panels that is the count value
javax.swing.JPanel[] panels = new javax.swing.JPanel[z];
for (int x = 0; x < z; x++){
String tabNumber = String.valueOf(x);
String tabName = "newPanel" + tabNumber;
panels[i] = new javax.swing.JPanel();
panels[i].setName(tabName);
jTabbedPane1.addTab("tabTitle", null, panels[i], null);
}
}
I don't have any idea if this compiles (my compiler is hours away) but this
is the general idea. If you can access your tabs (panels) by index you are
better off. Otherwise you have to declare seperate variables for each one.
Hope this helps,
Jeff Rafter
Realsoft Development
jeffrafter@earthlink.net
Technical Details
Message-ID:
<7832ob$cfa9@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<780uhe$aq55@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,de56a2e57de1717 X-Google-Attributes: gidf74b3,public From: "Jeff Rafter" <jeffrafter@earthlink.net> Subject: Re: adding components with a function Date: 1999/01/19 Message-ID: <7832ob$cfa9@forums.borland.com> X-Deja-AN: 434587592 References: <780uhe$aq55@forums.borland.com> X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0518.4 Organization: Realsoft Development Newsgroups: borland.public.jbuilder.java.language