小编pde*_*ean的帖子

Java swing - 重新调整大小时重绘组件(JButtons和JLabel)

我有这个奇怪的问题.我的教授似乎无法复制它,他提供的帮助充其量是最小的.所以说到这一点.此代码在面板上生成JButton并添加到JFrame的内容窗格中:

public myPanel extends JPanel {
    static final long serialVersionUID = 1;
    public myPanel() {
        this.setPreferredSize(new Dimension(600, 40));
    }
    public void paintComponent(Graphics graphicsDrawer) {
        super.paintComponent(graphicsDrawer);
        this.add(new JButton("A Button"));
    }
}
Run Code Online (Sandbox Code Playgroud)

这是GUI代码

public class myGUI {
    public myGUI() {
    }
    public void showGUI() {
        JFrame frame = new JFrame("Issues!!!");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new myPanel());
        frame.pack();
        frame.setVisible(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后由该类运行GUI

// It is unnecessary to show here but I made a class that
// implements runnable that creates a myGUI object and calls
// …
Run Code Online (Sandbox Code Playgroud)

java swing resize duplicates jbutton

3
推荐指数
1
解决办法
856
查看次数

标签 统计

duplicates ×1

java ×1

jbutton ×1

resize ×1

swing ×1