我使用Eclipse进行设计,但面板有一个定义的大小,它不会使用更多的组件。我试图使它可滚动并添加更多,但没有工作。如果有人知道如何或有更好的主意,请帮助。
是这样的:
public class Makeup {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Makeup window = new Makeup();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Makeup() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setUndecorated(true);
frame.getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(Color.PINK);
panel.setBounds(0, 0, 755, 660);
frame.getContentPane().add(panel);
panel.setLayout(null);
JPanel panel_2 = new JPanel();
panel_2.setBackground(new Color(250, 240, 230));
panel_2.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
panel_2.setBounds(100, 5, 555, 50);
panel.add(panel_2);
panel_2.setLayout(null);
JLabel lblNewLabel = new JLabel("Makeup Shop");
lblNewLabel.setBounds(0, 0, 555, 50);
panel_2.add(lblNewLabel);
lblNewLabel.setFont(new Font("Edwardian Script ITC", Font.BOLD, 55));
lblNewLabel.setBackground(new Color(250, 240, 230));
lblNewLabel.setForeground(new Color(255, 105, 180));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
JPanel panel_3 = new JPanel();
panel_3.setBackground(new Color(250, 240, 230));
panel_3.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
panel_3.setBounds(5, 65, 745, 35);
panel.add(panel_3);
panel_3.setLayout(null);
JLabel lblNewLabel_1 = new JLabel("Categories");
lblNewLabel_1.setBounds(0, 0, 745, 35);
panel_3.add(lblNewLabel_1);
lblNewLabel_1.setForeground(new Color(255, 105, 180));
lblNewLabel_1.setFont(new Font("Edwardian Script ITC", Font.BOLD, 40));
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
JPanel panel_4 = new JPanel();
panel_4.setBackground(new Color(255, 228, 225));
panel_4.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
panel_4.setBounds(5, 105, 745, 30);
panel.add(panel_4);
panel_4.setLayout(null);
JLabel lblNewLabel_2 = new JLabel(" Lipstick & Lipgloss ");
lblNewLabel_2.setBackground(new Color(255, 228, 225));
lblNewLabel_2.setBounds(0, 0, 745, 30);
panel_4.add(lblNewLabel_2);
lblNewLabel_2.setFont(new Font("Edwardian Script ITC", Font.BOLD, 35));
lblNewLabel_2.setForeground(new Color(255, 105, 180));
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(8, 140, 170, 130);
panel.add(btnNewButton);
JButton btnNewButton_1 = new JButton("New button");
btnNewButton_1.setBounds(198, 140, 170, 130);
panel.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("New button");
btnNewButton_2.setBounds(388, 140, 160, 130);
panel.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("New button");
btnNewButton_3.setBounds(578, 140, 170, 130);
panel.add(btnNewButton_3);
JButton btnNewButton_4 = new JButton("New button");
btnNewButton_4.setBounds(8, 320, 170, 130);
panel.add(btnNewButton_4);
JButton btnNewButton_4_1 = new JButton("New button");
btnNewButton_4_1.setBounds(198, 320, 170, 130);
panel.add(btnNewButton_4_1);
JButton btnNewButton_4_2 = new JButton("New button");
btnNewButton_4_2.setBounds(388, 320, 170, 130);
panel.add(btnNewButton_4_2);
JButton btnNewButton_4_3 = new JButton("New button");
btnNewButton_4_3.setBounds(578, 320, 170, 130);
panel.add(btnNewButton_4_3);
JButton btnNewButton_4_4 = new JButton("New button");
btnNewButton_4_4.setBounds(8, 500, 170, 130);
panel.add(btnNewButton_4_4);
JButton btnNewButton_4_4_1 = new JButton("New button");
btnNewButton_4_4_1.setBounds(198, 500, 170, 130);
panel.add(btnNewButton_4_4_1);
JButton btnNewButton_4_4_2 = new JButton("New button");
btnNewButton_4_4_2.setBounds(388, 500, 170, 130);
panel.add(btnNewButton_4_4_2);
JButton btnNewButton_4_4_3 = new JButton("New button");
btnNewButton_4_4_3.setBounds(578, 500, 170, 130);
panel.add(btnNewButton_4_4_3);
JButton btnNewButton_5 = new JButton("New button");
btnNewButton_5.setBounds(8, 720, 170, 130);
panel.add(btnNewButton_5);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new LineBorder(Color.PINK, 3));
panel_1.setBackground(new Color(250, 240, 230));
panel_1.setBounds(757, 0, 500, 660);
frame.getContentPane().add(panel_1);
panel_1.setLayout(null);
frame.setBackground(Color.PINK);
frame.setBounds(10, 10, 1260, 660);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
如果你想让它可滚动你应该使用JScrollPane,你可以使用这个java文档获取更多信息https://docs.oracle.com/javase/7/docs/api/javax/swing/JScrollPane.html