private JPanel contentPane;
public Driver() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 867, 502);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
final JTextArea textArea = new JTextArea();
textArea.setEditable(false);
textArea.setBounds(10, 11, 831, 393);
JScrollPane scroll = new JScrollPane(textArea);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
textArea.setText("dfgf");
contentPane.add(scroll);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Driver frame = new Driver();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
为什么这不显示textArea
滚动条?
我的问题是我什至看不到textArea。但如果我这样做contentPane.add(scroll);
,我可以看到 textArea 但没有滚动。