[英]why does text make my jbutton take up my whole jframe?
所以我正在使用 intellij 並試圖用文本制作一個 jbutton。 沒有文字它可以正常工作,但是當我把文字放在上面時,它占據了整個 jframe,我不知道為什么。 如果你能幫助我,我將不勝感激。 這是我的代碼。
package com.company;
import javax.swing.*;
import java.awt.*;
class Fantasyrpglifesim implements JButton {
Fantasyrpglifesim() {
}
public static void main(String[] args) {
MouseInputAdapter();
//Frame//
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
frame.setSize(1500000, 1500000);
frame.getContentPane();
frame.setVisible(true);
//Buttons//
frame.add(BUTTON).setBounds(570,500,150,150);
BUTTON.setText("Age up");
}
private static void MouseInputAdapter() {
}
}
您只需要更改 JFrame 的布局。 將下一行添加到您的代碼中:
frame.setLayout(new FlowLayout());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.