2017-05-06 50 views
0

我想放入一個JScrollPane一個JTextField,它可能嗎?這是我的代碼:如何添加一個JScroPane到JTextField

JTextField access; 

JPanel riga4 = new JPanel(); 

     JLabel label4=new JLabel("access"); 
     riga4.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 10)); 
     riga4.add(label4); 
     label4.setBorder(new EmptyBorder(10, 10, 10, 62)); 
     //riga4.add(label4); 

     access= new JTextField(15); 
     JScrollPane scrollPane = new JScrollPane(access);  
     riga4.add(scrollPane); 

任何人都可以幫助我嗎?

+0

你可能需要一個['JTextPane'(https://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html)或['的JTextArea '](https://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html)。 – Radiodef

+0

支持多行的正確組件是'JTextArea'。請參閱[如何使用文本區域](https://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html)。 –

+1

問題是什麼?文本字段中沒有文本,因此您將看不到滾動條。 – camickr

回答

0

你可以使用JTextArea中代替了JTextField

相關問題