3

I have simple JFrame window and its title keeps floating to the right (although written in english). Living in the middle east but using english version of Windows 7. what would be the correct way to align the title text properly and the left end of the title bar?

imports...

public class MainWindow extends JFrame {

    private JPanel contentPane;
    private final String arr[] = {"1","2","3","4","5","6","7","8","9","10"};

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MainWindow frame = new MainWindow("The Simulator");

                    frame.setVisible(true);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public MainWindow(String title) {
        super(title);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 582, 435);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

        JButton btnRandom = new JButton("Generate new random DCSP");
        contentPane.add(btnRandom);

        JButton btnManual = new JButton("Generate new manual DCSP");

        contentPane.add(btnManual);
    }

}

didn't help using

frame.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

or

frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.US));
Assaf Keret
  • 31
  • 1
  • 4
  • `The Simulator` appears left aligned on this machine, using the code shown (with imports). It seems it is [`Locale`](http://docs.oracle.com/javase/7/docs/api/java/util/Locale.html) dependent? – Andrew Thompson Dec 08 '12 at 23:03
  • This [L&F solution](http://stackoverflow.com/questions/6455831/set-jframe-orientation-from-right-to-left) may help you. – Reimeus Dec 08 '12 at 23:23

2 Answers2

1

What direction that the title text is aligned, really depends on the operating system that it is running on. I know that on my computer on windows 8 that the text is aligned in the middle, the same in osx but in windows 7 it is on the right. This solution is a workaround though but I don't know if it works on all operating systems.

Community
  • 1
  • 1
0

If I am not misinterpreting the question. You want to align the title text in different location. Such as Left, Center, or Right?

I think the position of the title bar is set by the OS. The new windows 8 sets all title in the center of the titlebar while windows 7 sets it to the left.

I think the work-around to this problem is seeing the space that the title is taking up and manipulate it by adding spaces.

I would try to set my title to a bunch of "AAAAAA" and see how many "AAAAA" does it take to fill up the whole titlebar,

For example if it takes 100 A's to fill up my titlebar and my width is 100 (minus the icon and the buttons) then I know every letter is taking 100/100=1 space. Knowing that, lets say I want to set the title to Hi" and align it to the right most corner, I can just add 98 blank spaces in front of "Hi"

Xiaoerge
  • 101
  • 1
  • 1