当我注释掉 frame.add(hidden) 它只显示文本区域。当我不评论它时,它只显示一个带有灰色滚动条的大灰色框。
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Panlindrome{
public Panlindrome(){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Panlindrome?");
frame.setSize(240,320);
//frame.setLayout(new GridLayout(3,1));
JTextArea inputText = new JTextArea(30,1);
inputText.setLineWrap(true);
JScrollPane hidden = new JScrollPane(inputText);
hidden.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.add(inputText);
//frame.add(hidden);
frame.setVisible(true);
}
public static void main(String[] args){
Panlindrome check = new Panlindrome();
}
}