我想在 JFrame 中的特定坐标上放置一个 Jbutton 。我为 JPanel(我放置在 JFrame 上)设置了 setBounds,还为 JButton 设置了 setBounds。但是,它们似乎没有按预期运行。
我的输出:
这是我的代码:
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
at坐标(0, 0)?