java中按钮的大小

See*_*tah 3 java swing jbutton layout-manager

在此输入图像描述

我想控制按钮的大小,我使用方法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 
Run Code Online (Sandbox Code Playgroud)

这主鳕鱼

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
Run Code Online (Sandbox Code Playgroud)

容器添加组件

   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)");
Run Code Online (Sandbox Code Playgroud)
    //add components for frame
Run Code Online (Sandbox Code Playgroud)
     cN.add(chooseLevel);
     cN.add(easyPuzzle);
     cN.add(mediumPuzzle);
     cN.add(hardPuzzle);
   }
   }
   }
Run Code Online (Sandbox Code Playgroud)

MBy*_*ByD 6

LayoutManager覆盖的边界设置了很多次,这是与案件GridLayout.

我建议你通过布局管理器教程.