我想在jButton上面設置我的jLabel。事實上,如果他們只是「漂浮」在彼此之上,那將是理想的。java JLabel不會重定位
Jet,我不能讓標籤顯示,因爲它停留在按鈕下方。我一直在google搜索和嘗試setLocation之類的東西,但無濟於事。我敢肯定,這是一件非常基本的,我很想念......
public class TranceExperiment extends JFrame {
public TranceExperiment() {
setTitle("Simple example");
setSize(600, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
TranceExperiment ex = new TranceExperiment();
ex.setVisible(true);
//set startLabel
JLabel expText = new JLabel("Welcome to the experiment");
ex.add(expText);
expText.setLocation(200,200);
//expText.setSize(100, 100);
expText.setVisible(true);
// expText.setLayout(null);
ex.add(expText);
//start Button
final JButton startButton = new JButton("Start");
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
//do stuff
startButton.setText("Continue");
}
});
ex.add(startButton);
}
});
}
}
嘗試使用佈局管理器嵌套其他組件內部的組件。 – Randy 2015-02-09 13:55:17
我不知道這是什麼意思 – dorien 2015-02-09 13:55:54
這不就是我在做什麼? HTTP://www.cs101。org/courses/fall05/resources/swinglayout/ – dorien 2015-02-09 13:56:34