我正在使用 MigLayout(我真的很喜欢它)。但是我在 JTextArea 前面的标签上遇到了问题。 我读过有关“基线”关键字的内容。但这与“成长”结合起来不起作用。
这是一个显示问题的示例。 我希望标签在顶部对齐(与 JTextArea 第一行的位置相同)。
有什么想法吗?
public class MigRunner {
public static void main( String[] args ) {
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
new MigRunner().run();
}
} );
}
@UiThread
private void run() {
JFrame frame = new JFrame();
Container contentPane = frame.getContentPane();
contentPane.setLayout( new MigLayout("wrap 2, fill, debug", "[][grow]", "[grow]") );
{
JLabel name = new JLabel( "Description" );
contentPane.add( name, "baseline" );
JTextArea textArea = new JTextArea();
JScrollPane scrollPane = new JScrollPane( textArea );
contentPane.add( scrollPane, "grow, baseline" );
name.setLabelFor( textArea );
}
frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
frame.setSize( 400, 300 );
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
}
最佳答案
也许您需要对齐约束:
JLabel name = new JLabel("Description");
contentPane.add(name, "aligny top");
在 Jeremias 发表评论之前,我没有看到文本基线之间有 3 个像素的间隙。好吧,我对此没有很好的解决方案,但这里有一个 Jeremias“gaptop 3”解决方案的附加想法:
JTextArea name = new JTextArea("Description");
name.setEditable(false);
contentPane.add(new JScrollPane(name), "aligny top");
关于java - Miglayout、基线和 JTextAreas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23708980/