Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical orientation of JTabbedPane titles when the tab placement is set to LEFT

As you can see from the image below, the Java text is horizontal. What I would like to do is get a vertical orientation of the JTabbedPane Titles.

While googling, I found that the only way is to add extra library. But I was wondering if this can be done without any extra library?

I would like for Title1 and Title2 to be vertically oriented and not horizontally

enter image description here

like image 271
Adel Boutros Avatar asked Dec 09 '22 03:12

Adel Boutros


1 Answers

You can use a JLabel with a custom LabelUI as described in this answer, it gives the result I expected:

Vertical text on JTabbedPane

JTabbedPane tabPane = new JTabbedPane(JTabbedPane.LEFT);

// Add tabs with no text
tabPane.addTab(null, component1);
tabPane.addTab(null, component2);

// Create vertical labels to render tab titles
JLabel labTab1 = new JLabel("Tab #1");
labTab1.setUI(new VerticalLabelUI(false)); // true/false to make it upwards/downwards
tabPane.setTabComponentAt(0, labTab1); // For component1

JLabel labTab2 = new JLabel("Tab #2");
labTab2.setUI(new VerticalLabelUI(false));
tabPane.setTabComponentAt(1, labTab2); // For component2
like image 165
Matthieu Avatar answered May 10 '23 11:05

Matthieu