如何垂直对齐JLabel-JTextField对 [英] How to align JLabel-JTextField pairs vertically

查看:688
本文介绍了如何垂直对齐JLabel-JTextField对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JLabel-JTextField对的意思是JLabel组件,后跟JTextField组,例如参数1:-----,其中-----表示空白的JTextField。



问题是,由于参数名称的长度不同,JLabel的宽度会有所不同,因此JTextField的起点不会垂直对齐。



有没有办法将JLabel垂直对齐到右边,以便后面的JTextField的开头会对齐?谢谢。

解决方案


有没有办法将JLabels垂直对齐到右边,这样就可以了接下来的JTextField的开头会对齐吗?


1.6 +,。



< img src =https://i.stack.imgur.com/6kpas.png>


What I mean by a JLabel-JTextField pair is a JLabel component followed by a JTextField one, for example, "Parameter 1: -----" where "-----" denotes a blank JTextField.

The problem is, the width of JLabels varies due to the varying lengths of parameter names, so that the starts of JTextFields are not aligned vertically.

Is there any way to align the JLabels vertically to their right, so that the starts of JTextFields that follow would be aligned? Thanks.

解决方案

Is there any way to align the JLabels vertically to their right, so that the starts of JTextFields that follow would be aligned?

1.6+, GroupLayout. E.G. from the JavaDocs:

Use the label alignment that pushes the text to the RHS.


See also this answer for an MCVE.

这篇关于如何垂直对齐JLabel-JTextField对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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