【发布时间】:2015-12-02 20:39:18
【问题描述】:
我使用GridBagLayout 并在其上放置JLabel,如图所示。我设法通过ipadx 和ipady 将JLabel 的大小设置为所需的大小,但我似乎无法使用它的位置。似乎它总是以中间为中心,而我想从红点开始并且在调整窗口大小时不要重新定位自己。我该怎么办?
谢谢。我使用的代码也是:
GridBagLayout gbl = new GridBagLayout();
setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints();
JLabel jl = new JLabel("This is a jlabel!", SwingConstants.CENTER);
jl.setBorder(BorderFactory.createLineBorder(Color.black));
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipadx = 87;
gbc.ipady = 220;
add(jl, gbc);
【问题讨论】:
-
玩锚和填充
标签: java swing awt gridbaglayout