Aneesh Ashutosh
Aneesh Ashutosh

Reputation: 772

JFrame Layout Alignment

I'm having a bit of trouble with JFrame layouts. What I want is this alignment: enter image description here but what I get with this snippet of code is this:

    this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.setLayout(new FlowLayout(FlowLayout.CENTER));

enter image description here

and with this snippet is this:

    this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    this.setLayout(new FlowLayout(FlowLayout.LEFT));

enter image description here

How can I get the ideal (where each row is centered but the icons start from the left side)?

EDIT: It's a bit hard to see the difference between the first and the last, but just open the images in a new tab and CTRL-TAB between them to see what I mean. In the first image, the entire thing is centered in the screen while in the third the icons are left-aligned. The second has ALL icons centered.

Upvotes: 0

Views: 96

Answers (1)

Aneesh Ashutosh
Aneesh Ashutosh

Reputation: 772

Alright, so I ended up just adding the images to a JPanel with the same left-to-right formatting as the third example and centering that JPanel. Simple fix.

Upvotes: 1

Related Questions