Question

I want to make a tabbed pane in my Swing GUI such that the tab headers appear as icons (i.e. I want to place a picture on the tabbed pane headers, like we can place pictures on buttons)

A GUI with tabbed pane headers appearing as icons (only pictures on those headers are visible, rest of the entire component is completely transparent), and when the user clicks on a picture/icon/tabbed pane header, the entire tabbed pane becomes translucent, and displays its contents (like text). The pictures attached show it better. Please note that there are no visible borders of the tabbed pane.

Is it possible? Any tips or suggestions are welcome?

Moreover, are such transparent and translucent swing components possible through the drag and drop facility of the NetBeans IDE?

enter image description here

When the user clicks:

enter image description here

I will be thankful for any ideas on how to do this.


enter image description here

Was it helpful?

Solution

For the tabs use addTab(null, icon, component) of JTabbedPane with icon the image you want and component a translucent JLabel. You can make one by calling its setOpaque(true) and setBackground(new Color(255, 255, 255, 100)).

Edit

Try to run this and see if it's getting closer to what you want.

public class TransparentTabs extends JFrame {

    private final static Color TRANSPARENT = new Color(0, 0, 0, 0);

    TransparentTabs() {

        JTabbedPane tabs = new JTabbedPane();

        JLabel label = new JLabel("Text Here");
        label.setOpaque(true);
        label.setBackground(TRANSPARENT);

        tabs.addTab(null, new ImageIcon("path to image"), label); // Change path
        tabs.addTab("Tab to the left has only an image", new JLabel("Something"));
        tabs.setSelectedIndex(-1);

        getContentPane().setBackground(Color.RED); // Placeholder for background image
        getContentPane().add(tabs);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        setVisible(true);
    }

    public static void main(String[] args) {

    UIManager.put("TabbedPane.contentAreaColor", TRANSPARENT);
    UIManager.put("TabbedPane.selected", TRANSPARENT);
    UIManager.put("TabbedPane.background", TRANSPARENT);
    UIManager.put("TabbedPane.borderHightlightColor", TRANSPARENT);
    UIManager.put("TabbedPane.darkShadow", TRANSPARENT);
    UIManager.put("TabbedPane.focus", TRANSPARENT);

        new TransparentTabs();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top