Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSyntaxTextArea not showing line numbers

I'm using RSyntaxTextArea for a minimized IDE I'm working on, Everything seems to be really working smoothly except for the line numbering, which I couldn't really make it show:

                RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
                textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
                textArea.setCodeFoldingEnabled(true);
                textArea.setAntiAliasingEnabled(true);
                RTextScrollPane sp = new RTextScrollPane(textArea);

                  sp.setLineNumbersEnabled(true);

                  sp.setFoldIndicatorEnabled(true);
                  if ( sp.getLineNumbersEnabled() )
                  {
                      System.out.println("Enabled"); // it prints the line but it's not showing 
                  }

                  contentPane.add(/*textEditorScrollPane*/ textArea, BorderLayout.CENTER);

I can't figure out why it's not showing the line numbers..

like image 383
geekybedouin Avatar asked Oct 15 '25 03:10

geekybedouin


1 Answers

It's not showing the scrollbars either, right? Assuming that contentPane is where you want your components, you need to add the RTextScrollPane instance to the contentPane, not the RSyntaxTextArea instance. The Gutter, which displays line numbers, is a part of the RTextScrollPane - an extended JScrollPane.

If you don't add a scroll pane to your GUI, it will not be shown, nor will you be able to scroll around. :P

So try the following:

contentPane.add(sp, BorderLayout.CENTER);
like image 59
predi Avatar answered Oct 17 '25 17:10

predi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!