java swing 设置了JTextArea的大小无法显示滚动条!?
大伙给个解决方法吧,多谢啦!代码如下:importjava.awt.*;importjavax.swing.*;publicclassMyScrollextendsJFr...
大伙给个解决方法吧,多谢啦!
代码如下:
import java.awt.*;
import javax.swing.*;
public class MyScroll extends JFrame {
/************创建组件*************/
JPanel centerPanel = new JPanel();
JTextArea textArea1 = new JTextArea();
JLabel blankLabel = new JLabel(" ");
JScrollPane scroll = new JScrollPane(textArea1);
/******************主函数*********************/
public static void main(String[] args) {
new MyScroll("月满西楼");
}
/**************构造函数**************/
public MyScroll(String title) {
super( "与 " + title + " 聊天中...");
centerPanel.setBackground(new Color(110,204,255));
centerPanel.setLayout(new BoxLayout(centerPanel,BoxLayout.X_AXIS));
textArea1.setPreferredSize(new Dimension(200,200));
add(scroll);
add(centerPanel);
//点关闭,释放窗口
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// 设置Window的布局管理器为BoxLayout
this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.setSize(300, 240);
this.setLocationRelativeTo(this);
this.setResizable(false);
this.setVisible(true);
}
} 展开
代码如下:
import java.awt.*;
import javax.swing.*;
public class MyScroll extends JFrame {
/************创建组件*************/
JPanel centerPanel = new JPanel();
JTextArea textArea1 = new JTextArea();
JLabel blankLabel = new JLabel(" ");
JScrollPane scroll = new JScrollPane(textArea1);
/******************主函数*********************/
public static void main(String[] args) {
new MyScroll("月满西楼");
}
/**************构造函数**************/
public MyScroll(String title) {
super( "与 " + title + " 聊天中...");
centerPanel.setBackground(new Color(110,204,255));
centerPanel.setLayout(new BoxLayout(centerPanel,BoxLayout.X_AXIS));
textArea1.setPreferredSize(new Dimension(200,200));
add(scroll);
add(centerPanel);
//点关闭,释放窗口
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// 设置Window的布局管理器为BoxLayout
this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.setSize(300, 240);
this.setLocationRelativeTo(this);
this.setResizable(false);
this.setVisible(true);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询