【发布时间】:2014-03-26 21:41:54
【问题描述】:
我是java的新学生。这是一个大学项目,一个gui中的数学测试。 我的对齐有问题。
我想在运行程序时在我的 gui 中执行此操作
Math Test - 10 exercises (this in the middle)
about 2 spaces here
1. How much is one added to one? ( this is an example. the math problems are going to be word problems with several sentences.)
a space here
Your answer, please. here goes a JTextField (4)
about 2 spaces here
2. here goes exercise number 2
etc. etc.
您认为数学题 JLabel 或 JTextArea 哪个更好?
这里我导入了 swing 和 awt
public class MathTest extends JPanel
{
public JTextField stu;
public MathTest() {
JLabel m=new JLabel ();
m.setText ("Math Test - 10 exercises");
add(m);
JLabel exone= JLabel();
exone.setText("1. how much is one added to one?");
add(exone);
JLabel y= new JLabel();
y.setText ("Your answer, please.");
add(y);
stu= JTextField (4);
add(stu);
}
}
程序可以运行,但我无法对齐标签和 JTextfield。
谢谢。
【问题讨论】:
-
你会想看看使用
LayoutManager。我个人的建议是非常灵活的MigLayout。学习需要一点时间,但非常值得。 -
截取它现在的样子可能会有所帮助,然后画出你想要的样子。
标签: java swing layout jpanel jlabel