Cannot change background color of button
I'm trying to change the background color of a button in my extension. Nothing I do will cause it to change from the colors of the buttons in the rest of the MD app. I found the following discussion:
https://infinitekind.tenderapp.com/discussions/moneydance-developme...
which suggested subclassing the button. I tried that exactly as written but I still don't get any change in my button color. I can change the font but not the color.
Any help would be appreciated.
This is my button class:
public class MyButton extends JButton {
public MyButton() {
super();
}
@Override
public void updateUI() {
super.updateUI();
this.setOpaque(true);
setBackground(Color.yellow);
}
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Bob B on 10 Jul, 2021 11:04 PM
Here is a screenshot of the window. The button labeled 'Show Returns' uses the new MyButton class, the others do not.
2 Posted by Stuart Beesley ... on 11 Jul, 2021 05:07 AM
Odd. I do this all this time. No subclassing, extension, or overrides... Example Jython script below (you can paste/run in Moneybot):
I know you're in pure java, but should be no different.....
3 Posted by Bob B on 12 Jul, 2021 04:13 PM
Thanks. I think the difference might be that I am running as an extension. I'm not the only one with the issue (see link in original post) but the solution there didn't work for me and I'm not sure why.
4 Posted by Bob B on 22 Jul, 2021 12:17 AM
Does anyone have an answer for me? I know it's not the end of the world but it's bugging me (mostly because I'm kinda new at this and can't figure it out).
Support Staff 5 Posted by Sean Reilly on 30 Jul, 2021 10:09 PM
Hi Bob,
We've added a lot of code recently to try to automatically keep button (and other UI component) colors inline with the currently selected color theme. So you will be working against the system (well, moneydance anyway) to override the colors. However I am surprised that setting the colors in updateUI() doesn't do the trick.
The only thing I can think of is to possibly call .updateUI() again after the button is created. I know that updateUI() is called in the super-class's constructor even before your own constructor is run, but calling it after your own button constructor might help a bit.
To be honest, I have gotten really frustrated dealing with swing's look and feels and color customisations, and I've probably hacked in some color overrides which weren't necessary.
Thanks,
Sean
--
Sean Reilly
Developer, The Infinite Kind
https://infinitekind.com
6 Posted by Bob B on 06 Oct, 2021 07:27 PM
I've done more research on this and the issue is with the WindowsLookAndFeel - it does not respond to background color changes for JButton. I found this and it solved the problem:
https://stackoverflow.com/questions/46823562/jbutton-background-col...
System closed this discussion on 05 Jan, 2022 07:30 PM.