0

I want to change the colour of the jTabbed Pane header(tab headers) and i want to get rid of the line which is separating the tab header and its body. I also like to have round edges for Tabbed Pane. How to do all these customization in swing? Is there any external jars available with this kind of inbuilt gui features. I don't want to use any look and feel to do this because many of them are also not customizable according to my need. As i am quite new to java please give me a detailed answer. Thanks in advance.

user3641302
  • 149
  • 1
  • 2
  • 13
  • It sounds like you might want to try changing the [look-and-feel](http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/) – gla3dr Jul 04 '14 at 15:21
  • No look and feel doesn't work at all. If i use a look and feel i have to stick to the colours that they are using – user3641302 Jul 04 '14 at 15:41

1 Answers1

1

For more complex look-and-feel changes you should take a look into writing your own look-and-feel like glad3r already mentioned. This post also is a great example.

For some basic things you might simply want to change some UIManager values, see example below and play a bit around with those values.

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import javax.swing.plaf.BorderUIResource;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.InsetsUIResource;

@SuppressWarnings("serial")
public class TabbedPaneTest extends JTabbedPane {

    public static void main(String[] args) {

        JFrame frame = new JFrame("TabbedPane");
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setBackground(Color.RED);
        frame.getContentPane().add(new TabbedPaneTest());
        frame.setVisible(true);
    }

    public TabbedPaneTest() {

        UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(1, 0, 0, 0));
        UIManager.put("TabbedPane.contentAreaColor", new ColorUIResource(Color.GREEN));
        UIManager.put("TabbedPane.focus", new ColorUIResource(Color.ORANGE));
        UIManager.put("TabbedPane.selected", new ColorUIResource(Color.YELLOW));
        UIManager.put("TabbedPane.darkShadow", new ColorUIResource(Color.DARK_GRAY));
        UIManager.put("TabbedPane.borderHightlightColor", new ColorUIResource(Color.LIGHT_GRAY));
        UIManager.put("TabbedPane.light", new ColorUIResource(Color.WHITE));
        UIManager.put("TabbedPane.tabAreaBackground", new ColorUIResource(Color.CYAN));
        UIManager.put("ToolTip.background", Color.WHITE);
        UIManager.put("ToolTip.border", new BorderUIResource(new LineBorder(Color.BLACK)));
        this.updateUI();

        this.setBackground(Color.BLUE);

        JPanel testPanel = new JPanel();
        testPanel.setLayout(new BorderLayout());
        testPanel.add(new JLabel("Hello World"), BorderLayout.NORTH);
        testPanel.add(new JTextArea("Looks nice out there :)"), BorderLayout.CENTER);

        JPanel testPanel2 = new JPanel();
        testPanel2.setLayout(new BorderLayout());
        testPanel2.add(new JLabel("Good Bye World"), BorderLayout.NORTH);
        testPanel2.add(new JTextArea("AAAAAnnnnnd... I'm gone"), BorderLayout.CENTER);

        this.addTab("Hello World", testPanel);
        this.addTab("BB World", testPanel2);
    }
}
Community
  • 1
  • 1
BenGe89
  • 141
  • 1
  • 7