我正在调用对数组进行排序的方法。排序工作正常,但是,我的外部区域上的滚动窗格不起作用,我尝试设置首选的大小和其他修复程序,但似乎没有任何作用
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
public class TextAreaDemo extends JPanel{
JTextArea text = null, answer = null;
public TextAreaDemo(){
text=new JTextArea("Hi all,\nI'm writing a program that populates a textarea with medical terms and " +
"such. And, the problem is I need to give an explanation to the more difficult words " +
"by allowing the user to click on the words and a popup window with the explanations " +
"will appear. I'm not familiar with the mouse clicks technology in Java, so please " +
"help if you can!\n\nAlso, any suggestions on how the data can be stored/retrieved " +
"when I'm using a MySQL database?\n\nMany thanks!");
answer=new JTextArea(3, 20);
answer.setEditable(false);
setLayout(new BorderLayout());
add(new JScrollPane(text));
add(new JScrollPane(answer), BorderLayout.NORTH);
text.addMouseListener(new MyMouseListener());
}
class MyMouseListener extends MouseAdapter{
public void mouseClicked(MouseEvent e){
if(e.getClickCount() == 2){
answer.setText("Do you want to know about:\n\t" + text.getSelectedText());
}
}
}
public static void main(String argv[]){
JFrame frame=new JFrame();
frame.setContentPane(new TextAreaDemo());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setVisible(true);
}
}