java - java中按钮的大小

标签 java swing jbutton layout-manager

enter image description here

我想控制按钮的大小,我使用方法 setBounds 但是没有改变 这是我的代码

       public class levels extends JFrame implements ActionListener{

 //Variables 
private static JLabel chooseLevel;
private static JButton easyPuzzle;
private static JButton mediumPuzzle;
private static JButton hardPuzzle;
 // End Of Variables 

这条主线

public static void main(String[]args){

levels level = new levels();
level.setBounds(400, 190, 450, 450);
level.setVisible(true); // frame is visible
level.setResizable(false); // not Resizable frame 
level.setTitle("Puzzle Number : New Game");  // Title Of the frame

添加组件的容器

   Container cN = level.getContentPane(); //  Container to add components for farme 1
   GridLayout gN = new GridLayout(0,1,10,20); //object from GridLayout
   cN.setLayout(gN);

   levels.chooseLevel = new JLabel("              Choose a level :");
   levels.easyPuzzle = new JButton("Easy puzzle from ( 1 - to -15)");
   levels.mediumPuzzle = new JButton("Medium Puzzle from (1- to- 29)");
   levels.hardPuzzle = new JButton("Hard Puzzle from (1- to- 59)");
    //add components for frame
     cN.add(chooseLevel);
     cN.add(easyPuzzle);
     cN.add(mediumPuzzle);
     cN.add(hardPuzzle);
   }
   }
   }

最佳答案

LayoutManager 多次覆盖您设置的边界,GridLayout 就是这种情况。

我建议你通过 layout managers tutorial .

关于java - java中按钮的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10502830/

相关文章:

java - 将Drawable类的对象存储在数据库中

java - mvn install 找不到安装在本地存储库上的本地工件

java - Java进度条不更新

java - 构建动态 JPanel 的最佳方法

java - 为什么我的 JButton 在不同的计算机上看起来不同?

java - 如何设置输出流指向的字节?

java - 用于提取所有可能金额的正则表达式

Java:无法让 JButton 水平紧贴文本

java - if 语句不在 while(true) 循环中执行

java - 仅当变量达到特定值时使按钮可见不起作用