• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTabbedPane

 
Fabiola Figueiredo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody!
I've just created a screen using JTabbedPane. My problem is to show the content for each tab selected.
I know I have to use the getSelectedIndex()... but I don't know where!?!?!?
Could anyone help me please?
Following is my code:
String string[] = { "One", "Two", "Three", "Four" };
pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
for (int i=0; i < string.length; i++) {
JPanel panelQ = new JPanel(new BorderLayout());
JButton buttonQ = new JButton(string[i]);
panelQ.add(buttonQ);
pane.add(string[i], panelQ);
}
JFrame frame = new JFrame(guiText.sFrameTitle);
frame.getContentPane().add(pane, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1000, 600);
frame.show();
Thanks!
 
Jason Dobies
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you clarify what your question is? I ran the code you supplied and I got four tabs successfully.
 
Fabiola Figueiredo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fou replying!
Fortunately, I could go further.....
Now I'm able to determine the index for selected tab.
My problem is: how can I show a different window for each tab.
For example:
Each tab has a specific title:
String stitleaux [] = {"Monday", "Tuesday", "Wednesday", "Thrusday"};
Each tab has a specific message in the bottom of the page.
String smessageaux [] = {"bla, bla, bla",
"hello, hello",
"have a nice day",
"how are you?"};
Then, I applied the following code:
String string[] = {"One", "Two", "Three", "Four"};
pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
for (int i=0; i < string.length; i++) {
JPanel panelQ = new JPanel(new BorderLayout());
JButton buttonQ = new JButton(string[i]);
panelQ.add(buttonQ);
pane.add(string[i], panelQ);
}
pane.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e){
pane_stateChanged(e);
}
});
...
public void pane_stateChanged(ChangeEvent e) {
selectedPanel = pane.getSelectedIndex();
System.out.println("Tab Index: " + selectedPanel);
if (selectedPanel == 3){ // for tab="Four" index=3
sTitle = stitleaux[selectedPanel];
sMessage = smessageaux[selectedPanel];
}
repaint();
}
When I execute the program, if the tab "Four" is selected, nothing happens, I mean, the title and the message have not been displayed.
I inserted System.out.println("Title = " + sTitle);
I inserted System.out.println("Message = " + sMessage);
and the variables are set up.
What am I missing?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!