java jpanel换行 10
1个回答
2017-08-09
展开全部
代码:importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassSimpleTestextendsJFrame{privateImageIconimage;privateJLabellabel;privateJButtonbutton;privateJPanelbuttonPanel,imagePanel;privateJScrollPanescrollPane;privateContainercontainer;publicSimpleTest(intxPixels,intyPixels){super("AddImage");button=newJButton("AddImage");image=newImageIcon("C:/1.jpg");imagePanel=newJPanel(newFlowLayout(FlowLayout.LEFT,5,5));scrollPane=newJScrollPane(imagePanel);button.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){label=newJLabel(image);imagePanel.add(label);validate();}});buttonPanel=newJPanel(newGridLayout(1,5));buttonPanel.add(button);container=getContentPane();container.setLayout(newGridLayout(2,1));container.add(buttonPanel);container.add(scrollPane);setSize(xPixels,yPixels);setVisible(true);}publicstaticvoidmain(String[]args){newSimpleTest(400,400);}}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询