user1133672
user1133672

Reputation: 1

Open Tab on WebTabbedPane on Button Click event in Swing.?

I have 4 tab and use WebTabbedPane.

Now, I want to One button that help to move to Other Tab. What to write in Button Click event that help move to Particular Tab in Swing

I have added Tab with Following Code.

WebTabbedPane tabbedPane = new WebTabbedPane(); tabbedPane.setPreferredSize(new Dimension(300, 200));

    tabbedPane.addTab("File Selection", fileView);
    tabbedPane.setSelectedForegroundAt(tabbedPane.getTabCount() - 1,
            Color.BLACK);

    tabbedPane.addTab("Criteria Selection", criteriaView);
    tabbedPane.setSelectedForegroundAt(tabbedPane.getTabCount() - 1,
            Color.BLACK);

    tabbedPane.addTab("Channels Selection", channelSelection);
    tabbedPane.setSelectedForegroundAt(tabbedPane.getTabCount() - 1,
            Color.BLACK);

    tabbedPane.addTab("Chart Preview", chartpreview);
    tabbedPane.setSelectedForegroundAt(tabbedPane.getTabCount() - 1,
            Color.BLACK);

Upvotes: 0

Views: 515

Answers (2)

MadProgrammer
MadProgrammer

Reputation: 347314

Well, you need to know the currently selected tab JTabbedPane#getSelectedIndex and then set the next or previous selected tab, JTabbedPane#setSelectedIndex.

Now obviously, you need to check to see if the new index is within the available range of selected tabs, but since you've already done something along the line, you should be able to figure it out.

The only other problem is you action handler is going to need a reference to the tabbedPane. Meaning it's either going to have to be a instance variable or past to the handler directly

I'd also suggest taking a look at How to use Tabbed Panes

Upvotes: 2

camickr
camickr

Reputation: 324137

Read the JTabbedPane API there are methods that allow you to get the currently selected tab and to set the current tab.

So in your ActionListener you would get the current tab, add 1 and then set the selected tab.

Upvotes: 2

Related Questions