【问题标题】:why does text make my jbutton take up my whole jframe?为什么文本让我的 jbutton 占据了我的整个 jframe?
【发布时间】: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() {
    }
}

标签: java intellij-idea text jframe jbutton


【解决方案1】:

您只需要更改 JFrame 的布局。将下一行添加到您的代码中:

frame.setLayout(new FlowLayout());
  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 2014-03-01
    • 1970-01-01
    • 2019-06-15
    • 2015-05-11
    • 1970-01-01
    • 2018-03-12
    相关资源
    最近更新 更多