Pluggable toolbar UI not working?
Answered
I am trying to override the toolbar's UI through javax.swing.plaf.ToolBarUI
This works for other UI elements, but I can not seem to get it work for the toolbar. Any advice?
From the UIManager I can retrieve the following info:
ToolBarUI = javax.swing.plaf.metal.MetalToolBarUI
So I assume it can be overridden:
UIManager.getDefaults().put("ToolBarUI", MyToolBarUI.class.getName());
UIManager.getDefaults().put(MyToolBarUI.class.getName(), MyToolBarUI.class);
and then be usable like so:
public class MyToolBarUI extends MetalToolBarUI implements DumbAware {
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
public static ComponentUI createUI(JComponent c) {
System.out.println("this should work??");
return new MyToolBarUI();
}
Not working unfortunately :(
Please sign in to leave a comment.
Is this for a plugin's UI? If yes, why do you need to override the UI?
Yann Cebron I wanted to change the current UI of the toolbar for a custom look and feel for my theme (something more than just the color).
While I'm at it, could you also have a look a the following code?
I got this from com.intellij.ui.components.JBScrollBar which states it supports a method for a custom UI.
So I implemented the code below (which works btw, I can override it) , but none of the extended methods affect the scrollbars in the UI.
How can I fix this?
public class MyScrollBarUI extends ScrollBarUI implements DumbAware {@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
public static ComponentUI createUI(JComponent c) {
// this works btw...
return new MyScrollBarUI();
}
}
Ok so, MyScrollBarUI extended by ButtonlessScrollBarUI kinda works as I can retrieve some information from its extended methods.
But methods like getPreferredSize do not work. I was curious as to why ScrollBar.width was not affecting the scrollbars (it is used in javax.swing.plaf.basic.BasicScrollBarUI). Seems like a deprecated setting?
So I assume JBScrollBar is responsible for setting the size now.
Now what I dont understand is why that class states to support a custom UI, when in reality I cant really use it.
What kind of toolbar you're trying to patch? We don't use javax.swing.JToolBar at all.
Actually we use JBScrollBar and as you can see in com.intellij.ui.components.JBScrollBar#createUI there are two options for UI: MacScrollBarUI and DefaultScrollBarUI
If I'm not mistaken ButtonlessScrollBarUI is Editor-specific case.