我想在JFrame的特定坐标上放一个Jbutton。我把setBounds放在JPanel(我放在JFrame上),还为JButton设置了Bounds。但是,他们似乎没有按预期的方式运作。
我的输出:
这是我的代码:
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Control extends JFrame {
// JPanel
JPanel pnlButton = new JPanel();
// Buttons
JButton btnAddFlight = new JButton("Add Flight");
public Control() {
// FlightInfo setbounds
btnAddFlight.setBounds(60, 400, 220, 30);
// JPanel bounds
pnlButton.setBounds(800, 800, 200, 100);
// Adding to JFrame
pnlButton.add(btnAddFlight);
add(pnlButton);
// JFrame properties
setSize(400, 400);
setBackground(Color.BLACK);
setTitle("Air Traffic Control");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new Control();
}
}
如何将JButton置于坐标(0,0)?