我試圖將此應用程序的組件設置爲使用setLocation的設置位置,到目前爲止我還沒有能夠移動組件。有更多的代碼,但它的調用和設置大部分代碼。有任何想法嗎?如何使用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);
}
}
也許你有一個佈局,不允許你自由移動的部件 – Evans 2013-05-08 16:52:01
不要使用'setLocation /的setSize/setBounds',這是一個佈局管理 – 2013-05-08 17:34:09