nick zoum
nick zoum

Reputation: 7305

Create Custom Look and Feel for a JTabbedPane

I am trying to create a JTabbedPane that will always fill the top part of the Component with the tabs. Like so:

And this is how it look now:

And the code for this part:

    JTabbedPane tab = new JTabbedPane();
    tab.addTab("Items", items);
    tab.addTab("Categories", categories);
    setContentPane(tab);
    //Also tried to create a JTabbedPane class and see if i could remove the labels and manually add two buttons to the top but without success.

I want the tabs to use up as much space as possible without actually shrinking the content of the panels. So could anyone tell me how to customize the JTabbedPane, the look and feed or just the tabs themselves in order to do that.

Upvotes: 1

Views: 804

Answers (1)

camickr
camickr

Reputation: 324127

The easiest approach is probably to create your own component:

  1. Create a "main" panel that uses a BorderLayout.
  2. Create a panel that uses a GridLayout and add your buttons to this panel. Then add this panel to the "main" panel using BorderLayout.PAGE_START. Each of these button will display a specific panel when clicked.
  3. Create a second panel that uses a CardLayout. Add this panel to the "main" panel using BorderLayout.CENTER. Each of these panels will represent a tab.

The other option is to look at the TabbedPaneUI and find a method that paints each tab and modify the code for your requirement.

Upvotes: 3

Related Questions