gpt4 book ai didi

java - 如何使用 set Location 移动组件

转载 作者:行者123 更新时间:2023-11-29 05:44:02 33 4
gpt4 key购买 nike

我正在尝试使用 setLocation 将此应用程序的组件设置到设定位置,但到目前为止我还无法移动这些组件。有更多的代码,但它在大多数情况下会调用和设置此代码。有什么想法吗?

import javax.swing.*;



public class HangmanPanel extends JPanel {
private static final long serialVersionUID = -5793357804828609325L;

public HangmanPanel(){

JLabel heading = new JLabel("Welcome to the Hangman App");
JButton Button = new JButton("Ok");
//Button.addActionListener();
JLabel tfLable = new JLabel("Please Enter a Letter");
JTextField text = new JTextField(10);

String input = text.getText();
heading.setLocation(50, 20);
tfLable.setLocation(20, 100);
text.setLocation(320, 50);
Button.setLocation(230, 100);

this.add(heading);
this.add(tfLable);
this.add(text);
this.add(Button);
}
}

最佳答案

您不应该使用 setLocation() 来布局 Swing 组件,使用 Layout 会好得多。请看these Layout Tutorials .

关于java - 如何使用 set Location 移动组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16446056/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com