How to set the color of a text selection?

Questions on using RSyntaxTextArea should go here.

Moderator: robert

How to set the color of a text selection?

Postby Endogen » Sat Jan 04, 2014 5:22 pm

I want to change the default color of selected text. I tried
Code: Select all
setSelectedTextColor(Color.black);
but that didn't change the color. How can i achieve that?
Example:

java code:

public class TextEditorDemo extends JFrame {

public TextEditorDemo() {

JPanel cp = new JPanel(new BorderLayout());

RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);

textArea.setSelectedTextColor(Color.black); // Doesnt work??

RTextScrollPane sp = new RTextScrollPane(textArea);
cp.add(sp);

setContentPane(cp);
setTitle("Text Editor Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);

}

public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TextEditorDemo().setVisible(true);
}
});
}
}
Endogen
 
Posts: 5
Joined: Sat Jan 04, 2014 10:18 am

Re: How to set the color of a text selection?

Postby robert » Wed Jan 08, 2014 1:27 pm

By default RSTA still colors tokens with their syntax highlighting colors when selected. To turn this off, call:

java code:

textArea.setUseSelectedTextColor(true);


Then, you can fetch the "right' color for the selection background and selected text from the UIManager. Alternatively, you can use the "default-alt.xml" theme shipped with the RSTA source to automatically load a theme that sets up the selection to use the L&F defaults. Or write your own theme and load it. More information about that here.
User avatar
robert
 
Posts: 794
Joined: Sat May 10, 2008 5:16 pm

Re: How to set the color of a text selection?

Postby Endogen » Wed Jan 08, 2014 7:22 pm

Thanks for the help, worked. :)
Endogen
 
Posts: 5
Joined: Sat Jan 04, 2014 10:18 am


Return to Help

Who is online

Users browsing this forum: Bing [Bot] and 3 guests

cron