当我创建我的GUI时,我使用cardlayout来保存我的不同面板,因为我相信很多人都知道.这会将我的屏幕设置为我最大面板的宽度和高度.这会导致我的第一个屏幕的美观问题,这个屏幕比SudokuPanel和CalkuroPanel小得多.
当我换到更大的屏幕时,我尝试设置首选大小,但无济于事.
任何帮助链接到良好的信息或任何通常只会帮助的人将非常感激:).
请在下面找到我的主要课程(我在哪里画GUI):
import java.awt.*; import javax.swing.*; import java.util.*;
public class puzzleGUI{
private static JPanel screens;
public static String username;
static public void main (String[] args){
JFrame puzzle = new JFrame ("Sudoku/Calkuro Pro");
...
PuzzleStartPanel startPanel = new PuzzleStartPanel();
PuzzleChoosePanel choosePanel = new PuzzleChoosePanel();
PuzzleSudokuPanel sudokuPanel = new PuzzleSudokuPanel();
PuzzleCalkuroPanel calkuroPanel = new PuzzleCalkuroPanel();
screens = new JPanel(new CardLayout());
screens.add(startPanel,"start");
screens.add(choosePanel,"choosePuzzle");
screens.add(sudokuPanel,"sudoku");
screens.add(calkuroPanel,"calkuro");
screens.setPreferredSize (new Dimension(250,80));
puzzle.setJMenuBar(menuBar);
puzzle.getContentPane().add(screens);
puzzle.pack();
puzzle.setVisible(true);
puzzle.setResizable(false);
puzzle.setDefaultCloSEOperation (JFrame.EXIT_ON_CLOSE);
}
static public void getUsername(String str){
username = str;
}
static public void openWindow(String newFrame){
CardLayout cl = (CardLayout)(screens.getLayout());
cl.show(screens,newFrame);
}
}
编辑
在调用openWindow时重置首选大小后,brainblast试图打包框架,并且wolah,新框架大小:D
static public void openWindow(String newFrame,int a,int b){
CardLayout cl = (CardLayout)(screens.getLayout());
cl.show(screens,newFrame);
screens.setPreferredSize (new Dimension(a,b));
puzzle.pack();
}
最佳答案
原文链接:https://www.f2er.com/java/438222.html