【发布时间】:2022-08-14 06:38:49
【问题描述】:
所以我正在使用intellij,并试图用文本制作一个jbutton。没有文字它可以正常工作,但是当我把文字放在上面时,它会占用整个jframe,我不知道为什么。如果你能帮助我,我将不胜感激。这是我的代码。编辑感谢 Manchi 的回答,它运行良好,我不再寻找答案,但我不知道如何结束这个问题。
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() {
}
}
-
首先查看Laying Out Components Within a Container,尤其是
BorderLayout的工作原理,因为JFrame默认使用BorderLayout
标签: java intellij-idea text jframe jbutton