SceneBuilder how to remove style class? - java

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");

Related

Replace JTree handle icons

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.

Adding ColorPickerPreference Library when it's not a preference

I'm trying to add a ColorPicker to my app. I see a lot a of ColorPickers (the one frome the API'S Samples, the one from Cyanogen, the AmbilWarna library, the HoloColorPicker, and the ColorPickerPreference). I think that the best for my app is the last one, but I don't need to use it on a preference.
So, what I want is to use this library inside my project when I click a button, and then take the resulting code from the SharedPreferences(I think, I don't know it), and use that color as I want for my app.
I try to use only some of the classes (only ColorPickerDialog, ColorPickerView, ColorPickerPanelView and AlphaPatternDrawable) and then I think that I have to do:
ColorPickerDialog dialog = new ColorPickerDialog(Main.this, Color.BLACK);
dialog.show();
And now I don't know how can I have the selected color.
Also I added to my project the xml view.
Any idea?
To know what is the selected color you need to to:
color=dialog.getfinalColor();
So, I think that the problem was easy to solve it. But now the problem is find a listener to detect when the dialog is closed and then to save the variable "color".

Netbeans GUI Builder Private Members

I have an existing project for which i have decided to create a GUI for in Netbeans. The problem I am encountering is the fact that every component that i drag-and-drop is private in the source and is unmodifiable. Must i create getters for everything?
I mainly just need this problem resolved for appending to the TextArea.
Thank you in advance
If you want to change that globally, go to the options dialog, then select miscellaneous, and pick the gui builder tab. You can configure the default modifier there.
By right clicking on a component in the Inspector panel, you can influence the generated code, even though it is in an editor-fold and not directly editable. For example, right click on a JList and edit the Properties > model to add text entries; right click on Code > Post Creation Code to add a code snippet affecting the selection model:
itemList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Examine the code in the editor-fold to see the generated changes.
See also Introduction to GUI Building.
You should see some tags in the code, something to do with begin and end of variable area. Usually there are 2 different sets of tags, any code between those tags will regenerate when you modify the gui with the form builder.
You can write your own code outside of those tags and it should remain even after you make changes. Getters and setters are a good idea if you need to update your object from another class. I've done that before with some text areas where I had a utility class update the text in it.

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.

How do I add components at run time to a Swing UI created with Netbeans visual editor?

I am currently writing an application where the user has, at some point, to click a button which have been generated at run time. I know how to do it when writing all my swing code from scratch, but I'd like to take advantage of Netbeans' visual editor.
The generated UI code goes into an initComponents() method I can't modify since it is regenerated automatically from the visual form.
I'd like to have a panel I place at design time using the visual editor in which I could add the buttons at run time so that they fit nicely in the layout, but I don't know how to access the panel in a convenient way. Besides, there may be another method than using a panel.
So basically :
How do I locate a Swing component at run time ?
Is there a better way of integrating components created at run time in a generated Swing UI ?
Thanks for your help.
NetBeans-generated GUI classes store all the components in private variables. You can add a method into the generated class that returns the panel, and it will remain even as you do additional design.
If you're going to use a generated UI, then it's probably best to use a JPanel within that UI to "carve out" space for your own components. Otherwise, you'll have to worry about how your components affect the layout of the components placed by the UI.
Just because you are using NetBeans generated GUI classes doesn't mean that you have to use the Group layout for the panels. I find that switching it to a BorderLayout helps especially in cases where I want to add some dynamic user interface code.
It is possible to change private to protected/public by either right clicking on a component in the GUI-Designer, choosing properties and hitting the Source-tab or right clicking on a component and choosing "Modify Source" (or something like that) and setting the appropriate access modifier.
Or just export them via a getXYZComponent() method.
Locating the component should provide as being too difficult, as you built it with the designer and thus know each component.
For example, if you had a JTabbedPane and wanted to add tabs to it when the user hits a button or something like that, you would simply issue myJTabbedPane.add(myCustomComponent); et voila, a new tab appears.
It is also possible to modify the auto-generated code and/or the code used for auto-generation by using the "Modify source" dialog mentioned above, which can be really useful.

Categories