![](/img/trans.png)
[英]How to add a vertical and horizontal scroll bar in a JTextArea to view complete file - JAVA
[英]how do I add a horizontal and vertical scroll bar to my JTextArea (java)
有人可以幫我在JTextArea中添加垂直和水平滾動條嗎?
textarea1 = new JTextArea();
textarea1.setBounds(17,183,208,100);
textarea1.setBackground(new Color(40,40,40));
textarea1.setForeground(new Color(225,228,0));
textarea1.setEnabled(true);
textarea1.setFont(new Font("sansserif",0,12));
textarea1.setText(chat1);
textarea1.setBorder(BorderFactory.createBevelBorder(1));
textarea1.setVisible(true);
謝謝 :)
以下是如何實現的:
JTextArea ta = new JTextArea();
JScrollPane sp = new JScrollPane(ta); // JTextArea is placed in a JScrollPane.
將JTextArea包含在JScrollPane中之后,應將JScrollPane添加到文本區域應位於的位置。 在以下示例中,帶有滾動條的文本區域被添加到JFrame中:
JFrame f = new JFrame();
f.getContentPane().add(sp);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.