Remove vertical scroll of jTextArea

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PreethiGowri
    New Member
    • Oct 2012
    • 126

    Remove vertical scroll of jTextArea

    How do we remove vertical scroll bar of a jTextArea?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You can pass it to a scroll pane that has the required scrolling options set


    Code:
        JTextArea yourTextArea = ...;
    
            JScrollPane pane =  new JScrollPane(yourTextArea,JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    Comment

    • PreethiGowri
      New Member
      • Oct 2012
      • 126

      #3
      Its not showing any text inside it now

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Create a short example that demonstrates the problem and post it.

        Comment

        • PreethiGowri
          New Member
          • Oct 2012
          • 126

          #5
          Code:
           jTextArea2.setText("House No = "+house+","+add); //which almost comes upto 3 lines
                  jTextArea2.setLineWrap(true);
                  jTextArea2.setWrapStyleWord(true);
                  JScrollPane pane =  new JScrollPane(jTextArea2,
          JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
          When i do so i scrollpane is removed but text inside textarea is not displayed

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Must be something wrong with some code that you haven't posted because this doesn't show scroll bars

            Code:
            import javax.swing.JFrame;
            import javax.swing.JScrollPane;
            import javax.swing.JTextArea;
            import javax.swing.SwingUtilities;
            import javax.swing.UIManager;
            
            public class Test extends JFrame {
            
                private JScrollPane jScrollPane;
                private JTextArea textArea;
            
                public Test() {
                    initComponents();
                }
            
                private void initComponents() {
                    setSize(500, 500);
            
            
                    StringBuilder text = new StringBuilder();
                    for (int i = 0; i < 100; i++) {
                        text.append("Line number " + (i + 1)).append("\n");
                    }
                    textArea = new JTextArea(text.toString());
            
                    jScrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                    getContentPane().add(jScrollPane);
            
                }
            
                public static void main(String args[]) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            // Turn off metal's use of bold fonts
                            UIManager.put("swing.boldMetal", Boolean.FALSE);
                            new Test().setVisible(true);
                        }
                    });
                }
            
            }

            Comment

            Working...