java中怎么在JFrame中任意位置添加一个按钮button_如何使用Java将JButton放置在JFrame中的所需位置...

我想在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)?

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值