Search code examples
jscrollpanejtextarea

The bar in jScrollPane dissapears when jTextArea gets too big


When entering to many lines of text into a jTextArea, at some point the bar dissapears to scroll down. (Even without that bar, I'm able to scroll up/down but it looks nasty without it)

This is how it looks with the bar (on the right side).

And some lines later, after the bar got really small because of more lines, it dissapears at some point when adding more lines.

How do i fix this?


Solution

  • The best solution which I found was changing your Look and Feel Standard should look like this:

    public static void main(String args[]) {
    try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
    
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MainFrame().setVisible(true);
                }
            });
    
    
    }
    

    By changing Nimbus to one of the other themes you will also change the Slider.