java jframe pack,java – 如何将jscrollpane添加到jframe?

我有以下源代码…有人可以给我一个如何将jscrollpane添加到jframe的建议吗?我尝试了几次将它添加到jframe但没有任何进展.它甚至没有显示出来.

public class Form3 {

JFrame jframe = new JFrame("Etiket print.");

JPanel panel1 = new JPanel();

JPanel panel2 = new JPanel();

JPanel panel3 = new JPanel();

JPanel panel4 = new JPanel();

JScrollPane scrollFrame = new JScrollPane(panel2);

Color myBlue1Color = new Color(168, 175, 247);

Color myBlue2Color = new Color(139, 146, 255);

public Form3(){

jframe.setMinimumSize(new Dimension(1280, 1000));

panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));

panel2.setAutoscrolls(true);

jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//---------------------------------Header

panel1 = createSquareJPanel(Color.YELLOW, 600,200);

panel3 = createSquareJPanel(Color.GREEN, 400,200);

panel4 = createSquareJPanel(Color.white, 280,200);

JPanel container = new JPanel();

JPanel container1 = new JPanel();

JPanel container2 = new JPanel();

container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));

container1.setLayout(new BoxLayout(container1, BoxLayout.Y_AXIS));

container2.setLayout(new BoxLayout(container2, BoxLayout.X_AXIS));

container1.add(panel1);

container2.add(container1);

container2.add(panel3);

container2.add(panel4);

container.add(container2);

container.add(panel2);

{

for (int i=0; i<25; i++){

JPanel harnessPanel= new JPanel();

harnessPanel.setMinimumSize(new Dimension(1280, 70));

harnessPanel.setMaximumSize(new Dimension(1280, 70));

harnessPanel.setPreferredSize(new Dimension(1280, 70));

if(i%2==0) {

harnessPanel.setBackground(myBlue1Color);

}

else {

harnessPanel.setBackground(myBlue2Color);

}

panel2.add(harnessPanel);

harnessPanel.repaint();

harnessPanel.validate();

}

panel2.repaint();

panel2.validate();

}

jframe.add(scrollFrame);

jframe.add(container);

jframe.pack();

jframe.setLocationRelativeTo(null);

jframe.setVisible(true);

}

private JPanel createSquareJPanel(Color color, int size1, int size2)

{

JPanel tempPanel = new JPanel();

tempPanel.setBackground(color);

tempPanel.setMinimumSize(new Dimension(size1, size2));

tempPanel.setMaximumSize(new Dimension(size1, size2));

tempPanel.setPreferredSize(new Dimension(size1, size2));

return tempPanel;

}

public static void main (String args[]){

SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {

Form3 myF=new Form3();

}

});

};

}

我的应用图片:

实际状态:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值