| Author |
JTabbedPane
|
Fabiola Figueiredo
Greenhorn
Joined: Aug 19, 2003
Posts: 2
|
|
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
Joined: Aug 13, 2003
Posts: 20
|
|
|
Could you clarify what your question is? I ran the code you supplied and I got four tabs successfully.
|
JCP, JCD, WCD... and all around nice guy.
|
 |
Fabiola Figueiredo
Greenhorn
Joined: Aug 19, 2003
Posts: 2
|
|
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?
|
 |
 |
|
|
subject: JTabbedPane
|
|
|