小编Zul*_*ejo的帖子

JFrame:如何禁用窗口大小调整?

我正在创建一个JFrame,我称之为方法setSize(500, 500).现在,期望的行为是用户不应在任何条件下调整JFrame的大小.通过最大化或拖动边框.它应该是500x500.我该怎么做?我还附上了代码,以防你可以更好地指导我.

    package com.techpapa;    
    import javax.swing.*;  
    import java.awt.*;  
    import java.awt.event.*;  

    public class MainWindow extends JFrame{


private JTextField
            write;
private JRadioButton
            rb1,
            rb2,
            rb3;
private ButtonGroup
            bg;

private ActionListener al = new ActionListener(){
    public void actionPerformed(ActionEvent e){
        write.setText("JRadioButton : " + ((JRadioButton)e.getSource()).getText());
    }

};

public MainWindow(){
    //Frame Initialization
    setSize(500, 500);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(null);
    setTitle(".:JRadioButton:.");
    setVisible(true);

    //Components Initialization
    write = new JTextField(20);
    write.setEditable(false);
    rb1 = new JRadioButton("Male", false);
    rb1.addActionListener(al);
    rb2 = new JRadioButton("Female", false);
    rb2.addActionListener(al);
    rb3 = new JRadioButton("I …
Run Code Online (Sandbox Code Playgroud)

java swing jframe resizable

38
推荐指数
7
解决办法
10万
查看次数

标签 统计

java ×1

jframe ×1

resizable ×1

swing ×1