当前位置: 代码迷 >> Java相关 >> 怎样设置TextArea的最小尺寸?
  详细解决方案

怎样设置TextArea的最小尺寸?

热度:261   发布时间:2006-02-17 17:46:00.0
怎样设置TextArea的最小尺寸?
怎样设置TextArea的最小尺寸?主要是设置列数,我一程序里要用到TextArea 但是不按回车,他就老在第一行写,没完没了,我用setMinimumSize(Dimension d)的试过,完全没用,还有设置scrollBar的常数在构造方法里是不是这么声明?
TextArea t = new TextArea(30, 30, SCROLLBARS_HORIZONTAL_ONLY); 这样也没有用??晕
搜索更多相关的解决方案: 最小尺寸  TextArea  ONLY  Dimension  

----------------解决方案--------------------------------------------------------
cll19820814,
首先建议你使用JTextArea instead of using TextArea
给你一段代码的节选:

//Create a text area.
JTextArea textArea = new JTextArea(
"This is an editable JTextArea. " +
"A text area is a \"plain\" text component, " +
"which means that although it can display text " +
"in any font, all of the text is in the same font.");
textArea.setFont(new Font("Serif", Font.ITALIC, 16));
textArea.setLineWrap(true); // 注意这里!!! 这是实现自动换行的关键
textArea.setWrapStyleWord(true);
JScrollPane areaScrollPane = new JScrollPane(textArea);
areaScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
areaScrollPane.setPreferredSize(new Dimension(250, 250));

----------------解决方案--------------------------------------------------------
  相关解决方案