jscrollpane 中怎么添加两个控件,如上面有JLabel,下面有JButton。求指教。
1个回答
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JScrollPaneDemo
{
JScrollPane scrollPane;
public JScrollPaneDemo()
{
JFrame f = new JFrame("JScrollpane1");
Container contentPane = f.getContentPane();
JLabel label = new JLabel("Label");
JButton btn = new JButton("Button");
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(label, BorderLayout.CENTER);
panel.add(btn, BorderLayout.SOUTH);
scrollPane = new JScrollPane(panel);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
contentPane.add(scrollPane, BorderLayout.CENTER);
f.setSize(new Dimension(350, 220));
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
new JScrollPaneDemo();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询