我该如何调整在JPanel中的所有元素向左? [英] How can I align all elements to the left in JPanel?

查看:1035
本文介绍了我该如何调整在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 = 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

这篇关于我该如何调整在JPanel中的所有元素向左?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆