cryptopi
cryptopi

Reputation: 313

Force Horizontal Tab Text on Left Aligned JTabbedPane

I am trying to make a JTabbedPane in Java 7 on OSX that has tabs positioned to the left with their text horizontal (instead of vertical). However, with the code:

import javax.swing.*;
import java.awt.Dimension;


class Probs extends JDialog {
    JTabbedPane options = new JTabbedPane();
    Probs(JFrame owner) {
        //main constructor
        super(owner, "User Preferences", true);
        //set the tabs to be left aligned
        options.setTabPlacement(JTabbedPane.LEFT);

        //construct the authorization panel
        JPanel authorization = new JPanel();
        authorization.add(new JLabel("test"));
        options.addTab("test", authorization);

        add(options);
        setSize(new Dimension(300,300)); //should use pack here
        setResizable(false);
        setLocationRelativeTo(null);
        setVisible(true);           
    }

    public static void main(String[] args) {
        JFrame test = new JFrame();
        new Probs(test);
        test.dispose();
    }
}

I get a dialog box which looks like: this image

I would like the tab text to be horizontal (the 'test' title on the tab be oriented horizontally instead of vertically).

I searched around on Google for a while and have only run into occurrences wherein people wanted to achieve vertical text on their tabs, I could not manage to locate any in which people wanted to have horizontal text (what I am trying to achieve).

In particular, I am trying to achieve something which exactly looks like the image mentioned in the first post of this question. It is basically the exact opposite of that question because the person in that tab started with what I am trying to achieve (I believe). Basically, I am trying to determine how to create the image displayed in the first post of that question.

Can someone please tell me how to have left-oriented tabs while preserving horizontal tab titles (as opposed to vertical)?

Thank you for your time and assistance.

Upvotes: 4

Views: 2708

Answers (3)

Amadeu Barbosa
Amadeu Barbosa

Reputation: 344

The system look and feel at MacOSX didn't support what you want in JTabbedPane. You must create a customized JComponent to do this or to set the look and feel of your application to cross platform (java metal) as stated before by @MonkeySupersonic.

I suggest the readings:

Upvotes: 1

Monkey Supersonic
Monkey Supersonic

Reputation: 1254

The alignment is determined by your operating system. If you want to change the alignment of the tab text, you have to change the look and feel of your swing application. This worked for me. See here.

Upvotes: 1

Paul Samsotha
Paul Samsotha

Reputation: 208984

Again, since I can't replicate the problem, Try this suggestion:

    JPanel authorization = new JPanel();
    authorization.add(new JLabel("test"));
    options.addTab("", authorization);
    JLabel labTab2 = new JLabel("test");    // create a label
    options.setTabComponentAt(0, labTab2);  // set it to the component

Upvotes: 1

Related Questions