문제

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.

도움이 되었습니까?

해결책

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

다른 팁

You can set the background color of a JButton object with the method setBackground.

So:

JButtonName.setBackground(Color.ORANGE);

In addition to David's and mre's comments, JButtons and by extension JToggleButtons are not opaque by default, so the background is not painted. In addition to setting the background color, you also need:

jButtonName.setOpaque(true);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top