0
下面是我的代碼。我無法添加所有6個按鈕。一次只顯示Button1 - 3或Button4-6。無法顯示JFrame上的所有按鈕
請讓我知道我要去哪裏錯了。
// This class contains the main method and launches the Main screen
import javax.swing.*;
import java.awt.*;
public class LearningHome{
public static void main(String[] args){
JFrame mainFrame = new JFrame("Welcome to the Learning! ");
try {
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setSize(800, 800);
mainFrame.setVisible(true); // Without this property the frame will not be visible
FlowLayout mainLayout = new FlowLayout();
JPanel mainPanel = new JPanel();
mainPanel.setLayout(mainLayout);
mainPanel.add(new JButton(" Button 1 "));
mainPanel.add(new JButton(" Button 2 "));
mainPanel.add(new JButton(" Button 3 "));
JPanel subPanel = new JPanel();
subPanel.setLayout(mainLayout);
subPanel.add(new JButton(" Button 4 "));
subPanel.add(new JButton(" Button 5 "));
subPanel.add(new JButton(" Button 6 "));
mainFrame.add(mainPanel, mainLayout.LEFT);
mainFrame.setLocationRelativeTo(null);
mainFrame.add(subPanel, mainLayout.RIGHT);
}
}
PACK是一個不錯的選擇。但隨着我的網頁縮小,我不需要。除此之外,我已經實施了一切。你的解釋很棒。非常感謝。 –