public static void main(String[] args) {
JFrame jf=new JFrame();
jf.setSize(400,300);
jf.setLocationRelativeTo(null);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//创建文本
JTextArea textArea=new JTextArea();
textArea.setLineWrap(true); //制动换行
textArea.setFont(new Font("楷体",Font.PLAIN,22));
textArea.setForeground(Color.blue); //颜色
//创建滚动面板,指定显示组件
JScrollPane scrollPane=new JScrollPane(textArea,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, //设置垂直滚动条
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED //需要的时显示
//ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER //不显示水平滚动条。
);
jf.setContentPane(scrollPane);
jf.setVisible(true);
}
Swing测试滚动面板
最新推荐文章于 2023-12-03 19:13:37 发布