我该如何调整在JPanel中的所有元素向左?我该、元素、JPanel

由网友(南风旧巷)分享简介:我想在我的JPanel的所有元素对齐到左边。我尝试这样做以下列方式:I would like to have all elements in my JPanel to be aligned to the left. I try to do it in the following way:JPanel panel =...

我想在我的JPanel的所有元素对齐到左边。我尝试这样做以下列方式:

I would like to have all elements in my JPanel to be aligned to the left. I try to do it in the following way:

JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setAlignmentX(Component.LEFT_ALIGNMENT);

结果的Java使用的所有元素的左侧元素的位置,然后把所有元素的JPanel的中心(未留一部分)。

As a result Java use left side of all elements as a position of the element and then put all elements in the center (not left part) of the JPanel.

推荐答案

我发现左边的对象正在使用的FlowLayout把最简单的方法。

The easiest way I've found to place objects on the left is using FlowLayout.

JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));

添加成分通常这个小组将其放置在左侧

adding a component normally to this panel will place it on the left

阅读全文

相关推荐

最新文章