By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

Remove vertical scroll of jTextArea

100+
P: 126
How do we remove vertical scroll bar of a jTextArea?
Apr 19 '13 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
You can pass it to a scroll pane that has the required scrolling options set


Expand|Select|Wrap|Line Numbers
  1.     JTextArea yourTextArea = ...;
  2.  
  3.         JScrollPane pane =  new JScrollPane(yourTextArea,JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
Apr 19 '13 #2

100+
P: 126
Its not showing any text inside it now
Apr 19 '13 #3

10K+
P: 13,264
Create a short example that demonstrates the problem and post it.
Apr 19 '13 #4

100+
P: 126
Expand|Select|Wrap|Line Numbers
  1.  jTextArea2.setText("House No = "+house+","+add); //which almost comes upto 3 lines
  2.         jTextArea2.setLineWrap(true);
  3.         jTextArea2.setWrapStyleWord(true);
  4.         JScrollPane pane =  new JScrollPane(jTextArea2,
  5. JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
When i do so i scrollpane is removed but text inside textarea is not displayed
Apr 19 '13 #5

10K+
P: 13,264
Must be something wrong with some code that you haven't posted because this doesn't show scroll bars

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JFrame;
  2. import javax.swing.JScrollPane;
  3. import javax.swing.JTextArea;
  4. import javax.swing.SwingUtilities;
  5. import javax.swing.UIManager;
  6.  
  7. public class Test extends JFrame {
  8.  
  9.     private JScrollPane jScrollPane;
  10.     private JTextArea textArea;
  11.  
  12.     public Test() {
  13.         initComponents();
  14.     }
  15.  
  16.     private void initComponents() {
  17.         setSize(500, 500);
  18.  
  19.  
  20.         StringBuilder text = new StringBuilder();
  21.         for (int i = 0; i < 100; i++) {
  22.             text.append("Line number " + (i + 1)).append("\n");
  23.         }
  24.         textArea = new JTextArea(text.toString());
  25.  
  26.         jScrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  27.         getContentPane().add(jScrollPane);
  28.  
  29.     }
  30.  
  31.     public static void main(String args[]) {
  32.         SwingUtilities.invokeLater(new Runnable() {
  33.             @Override
  34.             public void run() {
  35.                 // Turn off metal's use of bold fonts
  36.                 UIManager.put("swing.boldMetal", Boolean.FALSE);
  37.                 new Test().setVisible(true);
  38.             }
  39.         });
  40.     }
  41.  
  42. }
Apr 19 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.