【发布时间】:2016-05-24 08:42:56
【问题描述】:
所以我用java的swing库做了一个程序。我制作了一个绘制方程式的程序,如果相关,这里是主要方法:
public static void main(String[] args) throws Exception {
JFrame frame= new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLayout(new GridLayout(1,2));
GraphPanel gp = new GraphPanel();
GraphPanel gp2 = new GraphPanel();
//gp.functs.add(new Function(Phrase.createPhrase("2(25-x^2)^(1/2)")));
//gp.functs.add(new Function(Phrase.createPhrase("-1.1((25-x^2)^(1/2))")));
gp.functs.add(new Function(Phrase.createPhrase("x^2")));
//gp.functs.add(new Function(Phrase.createPhrase("-4/x^2+6")));
gp2.functs.add(new Function(Phrase.createPhrase("sinx")));
frame.add(gp);
frame.add(gp2);
frame.pack();
frame.setSize(800, 800);
//gp.setBorder(BorderFactory.createLineBorder(Color.RED));
gp.setBounds(100, 100, 700, 700);//I WANT THIS TO ALWAYS RUN
}
我在未更改任何部分的情况下运行了该程序的两次试运行,这就是它的样子:
然后我下次运行它:
如果相关,GraphPanel 是 JLabel 类型。 我知道如果我使用 null 绝对 LayoutManager,它将始终有效。但我只是想知道为什么摇摆中有这样的不一致之处。我以前注意到过这样的事情,但我认为这只是程序中的一些错误。为什么是这样? 提前致谢!
【问题讨论】:
标签: java swing jlabel positioning absolutelayout