Search code examples
javaswingjbuttonjtogglebutton

Show user that something is on from JButton


Okay, I'll admit - the title is not the most descriptive/helpful but I couldn't really think of a better way to put it, which is probably also why I couldn't find an answer when I was searching.

Basically, I'm making a basic MS Notepad like text editor and I want to add two JButton's to make a JTextArea's font Bold and Italic. I need someway of indicating whether the text is currently bold and/or italic like in MS Office programs where the background of the buttons are orange when text is bold, italic or underlined - only I can't seem to change the background of the button. I think this is due to the fact that I am using the operating system's look and feel, but that information still doesn't solve my problem.

So does anyone have any suggestions on how I can provide some feedback as to whether the text is bold and/or italic through the JButton like in Microsoft Office Word? Thanks in advance.


Solution

  • Hmm...sounds like you'll want to make use of the JToggleButton class.