• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difficulty implementing JTabbedPane

 
Orville Redenbacher
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to learn how to use the TabbedPane GUI. I can get the tabs to show up, but the buttons I have placed in each tab do not show up. I have no idea why this is not working. I assume that, for some reason, the buttons are not linking with their respective panels, or the panels are not linking to the respective tabs.

 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you add the tabbed pane to the frame? I don't see that.

Also you should first add the components before setting the frame to visible and pack.

 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... apart from which, the variables tab1 and tab2 are still null when you add them to the tabbed pane.
 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good catch Darryl

It is probably better to make the "createtabX" methods return JPanel so that the "tabl1" and "tab2" variables can become local inside the methods.

 
Orville Redenbacher
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the repsonses. So I made a few adjustments and it is still not working. I re-ordered the calls to the JFrame as suggested:



Also I had seen several tutorials using the getContentPane method to attach everything to the JFrame, not sure why. I tested it like this : and it made no difference. I do not understand what was meant by "returning JPanel." Is this referring to adding tab1 and tab2 to the JTabbedPane tabs?

I had also seen several tutorials making a new instance of the class within the code, I do not understand why. Here is an example I found online...it may be too much info. You can see where the new instance is created in the createandshowGUI method towards the end. I have tried to translate this and several examples into my code, but with no success.

 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By returning JPanel in a method means something like:


Then for the frame:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!