滚动条未显示在JTextArea中

时间:2013-03-08 20:49:52

标签: java swing user-interface jscrollpane jtextarea

我正在尝试放置一个名为descriptionScroll的滚动文本区域。但是,滚动条不可见。我尝试了很多方法,但都以挫败感结束。

我是否遗漏了任何内容以显示滚动条?它应该出现在“描述”

旁边的大文本框的右侧

以下是相关代码:

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

protected JTextArea descriptionTextArea;


protected JScrollPane descriptionScroll;


String descriptionText = 
"Lot ID(s):\n" +
"Wafer ID(s):\n" +
"PSPT(Probe Ship Part Type):\n" +
"Tester:\n" +
"Tester Job Name:\n" +
"PID (FPP, FPC):\n" +
"Reprobe required before shipping lot? (Y/N)\n\n" +
"Hold for (individual):\n" +
"Hold for (group)\n" +
"Expected release date\n" +
"Hold Comments:\n\n" +
"Shipping Information:\n" +
"Special Instructions:\n";


public Constructor(){

descriptionTextArea = new JTextArea(descriptionText);
descriptionScroll = new JScrollPane(descriptionTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(descriptionTextArea);
add(descriptionScroll);  
pack();

setSize(790, 625);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);


descriptionTextArea.setSize(650, 200);
descriptionTextArea.setLocation(110, 228);
descriptionTextArea.setLineWrap(true);



}

Missing scroll

1 个答案:

答案 0 :(得分:3)

您将JScrollPane和JTextArea添加到同一容器中。将JTextArea添加到JScrollPane:

descriptionScroll.add(descriptionTextArea);