Replace JTree handle icons - java

I'm trying to customize a JTree so that I can use it in a project that I'm working on. That project GUI's style does not fit the default Java LNF's node handles for JTree which is why I tried to replace them with custom-made icons but I'm stuck as to how I can do that. I don't know if that helps but I already have an own LNF class which loads the default LNF settings and overrides some of them with custom values.
Alternatively, if replacing the handles' icons is too complex to explain it in an answer here, how can I completely disable them so that I can use custom open/closed icons for all expandable nodes?

By setting the UIManager properties Tree.collapsedIcon (for collapsed handles) and Tree.expandedIcon (for expanded handles) to the desired values, the handles for all JTrees can be changed at once. Thanks to #MadProgrammer for suggesting the examples shown here, here, here and here.

Related

SceneBuilder how to remove style class?

I want to style a RadioButton as a normal button, but keep the RadioButton's functionality.
Instead of writing this in my code:
radioButton.getStyleClass().remove("radio-button");
radioBUtton.getStyleClass().add("toggle-button");
I want to do it in SceneBuilder. I'm aware that SceneBuilder has this section in the Inspector Panel:
But I only know how to add style-classes, not remove them. So it still has the RadioButton styling with the dot on the left. How can I do this in SceneBuilder, or, if I can't, can I include it in the CSS somehow? Or must I have it done in the code itself?
There is definitely no way to accomplish your goal through Scene-Builder, since it was only developed in use as a UI Layout Tool. You can think of the manual adding and removing of a style class as a “preview” and current state of a class a node possesses but you cannot remove it again programmatically using the Builder.
The best way to solve this would be as you have already mentioned by applying this code into your controller-class:
radioButton.getStyleClass().remove("radio-button");
radioBUtton.getStyleClass().add("toggle-button");

How to change tabs location in JTabbedPane?

I want to change tabs location from left to center. How can I do this? I think I must change Look&Feel, but I don't know how.
From this:
To this:
As you already pointed out, you have to use an LookAndFeel which supports this design (centered Tab-Button).
When your selected LaF does not support this, you have to write your own TabbedPaneUI.
(But this may not be very easy.)
If you do not want to create your own TabbedPaneUI, you have to look for an existing custom TabbedPaneUI or TabbedPane-Component, which support this kind of layout.
You can take a look at this article, to get started:
http://www.javaworld.com/article/2072927/swing-gui-programmingloseandmaxtabbedpane--an-enha/swing-gui-programming/closeandmaxtabbedpane--an-enhanced-jtabbedpane.html
The placement of tabs is determined by the JTabbedPane UI delegate, typically based on BasicTabbedPaneUI. Not every Look & Feel implementation supports centered tabs, so there's no property that will work by default across platforms.
As a concrete example, com.apple.laf.AquaLookAndFeel supports centered tabs, as shown below. The class com.apple.laf.AquaTabbedPaneUI, which implements the effect, is shown here.
Because the implementation is non-trivial, a better choice is to support the user's Look & Feel choice using Preferences. A suitable Look & Feel selection control is shown here and here.
The source for the example above is seen here.

Is it possible to remove the little dropdown arrow in a JInternalFrame?

I'm using a JInternalFrame and I want to remove the dropdown in the upper left of the frame, as it serves no purpose (I've disabled resizeable, closable, etc.)
I don't see a property for this, and I don't want to remove the entire title bar, as the title is necessary. I've looked around online, and basically come up empty here. I'm hoping it's something simple that I've just overlooked, as this is my first time using JInternalFrame, and I'm not exactly a GUI kind of guy to begin with.
internalframe.setFrameIcon(null);
Edit: hack to remove system menu in Windows:
BasicInternalFrameUI ui = (BasicInternalFrameUI)internalFrame.getUI();
Container north = (Container)ui.getNorthPane();
north.remove(0);
north.validate();
north.repaint();
The relevant Icon in The Synth Look and Feel, among the Nimbus Defaults, appears to have this key:
InternalFrame:InternalFrameTitlePane:"InternalFrameTitlePane.menuButton".icon
You may be able to use the approach shown in A Synth Example to replace the Icon.
setFrameIcon(anyBigImageThatCantBeDisplayed);
I´ve tried null parameter and got some visual issues...
So i added a big image(no background) that was already on my resource folder and the icon was no longer displayed as the menu...

How do I prevent button surround from displaying in Java?

Sorry for the odd choice of words for the title, however, "border" seems to be the inappropriate term. While it is true that the visible line surrounding an icon in a JToggleButton can be made invisible by using setBorderPainted(false), the same is not true for JCheckBox and JRadioButton.
I can not use the JToggleButton and therefore need to use either the JCheckBox or JRadioButton (or some derivative of JToggleButton I am not aware of), but need the square or circle, respectively, to be non-visible when there is no icon on the button. Also, using setVisible(false) eliminates the button from the layout, however, I need the space to be reserved and not have the component layout change (using GroupLayout).
Any suggestions? Am I going to have to create a custom renderer? I will be looking at that in the mean time.
The route into this would be through customising the look at feel by changing some of the UI properties in the UImanager (the sort of thing that allows you to make simple tweaks with fonts and colours and presumably the images used for the checkboxes or radiobuttons) -- but it's many years since I last did that sort of thing and can't remember the details.
A little Googling turned up this project to inspect current property values, so might at least help with indicating the right part of the APIs to be looking at.
You have to choices here:
1) Customize Look and Feel as described in previous entry.
2) Create your own custom controls by inheriting from existing ones and overriding component painting.
I found a cheap and easy (read hack) for this. I created an empty transparent icon and used it when I didn't want any item to be displayed.

JTabbedPane: Components before and after the tabs themselves

This is similar to the question How to build a Google-chrome tabs and menubar interface in Java Swing? (I want to accomplish the same), but more to the point: How do I put components in front and behind the tabs in a JTabbedPane?
I've already come up with the buttons-idea myself, but I'd rather have a JTabbedPane, since that is really what it is, but decorated with a button or icons on the sides.
I've seen that the laf-widget project from Kirill does something like it (the magnifying-glass icon to the left of the tabs) for several LaFs. However, I must admit that I'm not yet well enough versed to understand how he does it - and also it seems like a somewhat complicated process, whereby one "physically" change the LaF in question (bytecode manipulates it), injecting the laf-widget stuff into the UI delegates - and I still don't know how the JTabbedPane or TabbedPaneUI is actually modulated to inject that icon/button.
I finally asked Kirill of Substance LaF/laf-widget of how he manages to put a button in front of the tabs in the laf-widget that decorates JTabbedPanes, and this is his reply:
It relies on the
BasicTabbedPaneUI.tabAreaInsets field
to make room for the button, and
custom setBounds of the button
component to position itself in that
area.
For more code, see TabOverviewButton
and TabOverviewDialogWidget classes in
the laf-widget project.
In general, the tabbed pane UI
delegate is one of the least
attractive ones to enhance since it
has a lot of private and package
protected methods
Thanks, Kirill!
JIDE have a tabbed pane as part of their component suite that exposes this functionality as simple setBeforeComponent() and setAfterComponent() methods.
There's a demo of it in here: http://www.jidesoft.com/products/1.4/jide_demo.jnlp

Categories