So, I'm wondering how I would go about colouring certain words in my scrollpane. After doing some research I have found almost nothing helpful. What is there to help with colouring certain words?
JScrollPane scrollPane = new JScrollPane();
contentPane.add(scrollPane, BorderLayout.CENTER);
txtInfo = new JTextArea("Bot In Progress...\n");
txtInfo.setColumns(35);
txtInfo.setEnabled(false);
txtInfo.setDisabledTextColor(Color.black);
scrollPane.setViewportView(txtInfo);
So, here is my scrollpane. What I have it doing now is accepting outputs from part of my program and displaying them. Certain words that I want coloured are Win!(Green) and Loose(Red), and maybe some more later.
The reason why a scrollpane works the best for me is because I need the log to update constantly and the user is supposed to be able to look back up at the log at any time. Is there a better way of storing that information or what?
I don't think you can do it with JTextArea instead you can do it using JTextPane. You can then add the JTextPane to your JScrollPane. Have a look at this site http://javatechniques.com/blog/setting-jtextpane-font-and-color/ where it explains how to do this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.