|
Replies:
12
-
Pages:
1
-
Last Post:
6 Aug 21, 09:34
Last Post By: davidekholm
|
Threads:
[
Previous
|
Next
]
|
|
Posts:
8,033
Registered:
31-Jan-2006
|
|
|
|
Forcing a radio button setting
Posted:
5 Aug 21, 03:03
|
|
|
|
|
An odd problem.... In one of my skins, the theme image choices used to consist of a JCheckbox for "Show theme images," followed by three radio buttons to choose the kind of theme image - see old.png. In the new version, I've replaced that with four radio buttons - see new.png.
The SkinModel.java defaults are straightforward enough: public boolean themeFolders = true;
public boolean themeSingle = false;
public boolean themeToponly = false;
public boolean themeNone = false;
And in the main Java: ButtonGroup themeScope = new ButtonGroup();
JRadioButton themeFolders = new JRadioButton("Use folder-specific theme images");
JRadioButton themeSingle = new JRadioButton("Use top-level theme image for all folders");
JRadioButton themeToponly = new JRadioButton("Use theme image on top level only");
JRadioButton themeNone = new JRadioButton("No theme image");
In the UI setup, I'm using my usual routine for detecting that a project was built with an older version, and correcting some variables. I've tested, and it is correctly determining that useThemes is, indeed, false in an older project. But even when I beat it to death, I can't get the radio buttons to load with the correct choice. if (!(Boolean) vars.get("useThemes")) {
vars.put("themeFolders", Boolean.FALSE);
vars.put("themeSingle", Boolean.FALSE);
vars.put("themeToponly", Boolean.FALSE);
vars.put("themeNone", Boolean.TRUE);
}
The UI always loads with the themeFolder choice selected. Any hints?
|
|
|
Posts:
3,948
Registered:
4-Aug-2006
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 12:32
in response to: JeffTucker
|
|
|
|
Is this a case where you need to use window.UI2Bean(); followed by window.bean2UI().
Or is that what you tried in ‘beating it to death’?
|
|
|
Posts:
8,033
Registered:
31-Jan-2006
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 13:03
in response to: RobM
|
|
|
|
No, this is all happening upon loading. I've never had to engage in any trickery to plant new values in there for other booleans (JCheckBox) or Strings, like a color or a JComboBox choice. There's something fundamentally different about a radio button, it seems.
In the "beating it to death" department I include setting all four of the button values - the only one that's wrong is themeFolders, which is true by default. I've also tried vars.remove() on each of them, which made no difference, of course. And I've planted console messages in there to confirm that the current value for themeFolders is true, and that it's false when I'm done. But open the settings window, and nothing has changed.
|
|
|
Posts:
3,822
Registered:
18-Oct-2002
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 13:31
in response to: JeffTucker
|
|
|
|
JRadioButtons are handled via the ButtonGroup component. Add it to the ControlPanel class instance instead of adding each individual JRadioButton. Now, call setActionCommand on each JRadioButton with the value you wish that option to deliver to the ButtonGroup component.
|
|
|
Posts:
8,033
Registered:
31-Jan-2006
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 14:00
in response to: davidekholm
|
|
|
|
I feel about two hours of "guess, crash, guess, crash, guess, crash" coming on....
|
|
|
Posts:
3,822
Registered:
18-Oct-2002
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 14:03
in response to: JeffTucker
|
|
|
|
Do you want me to write up a minimal example for the Minimal skin?
|
|
|
Posts:
8,033
Registered:
31-Jan-2006
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 14:27
in response to: davidekholm
|
|
|
Better, let me lay it out, and you can tell me what needs to be changed.
In SkinModel.java: public boolean themeFolders = true;
public boolean themeSingle = false;
public boolean themeToponly = false;
public boolean themeNone = false;
In Jupiter.java, in the ControlPanel ui setup: ButtonGroup themeScope = new ButtonGroup();
JRadioButton themeFolders = new JRadioButton("Use folder-specific theme images");
JRadioButton themeSingle = new JRadioButton("Use top-level theme image for all folders");
JRadioButton themeToponly = new JRadioButton("Use theme image on top level only");
JRadioButton themeNone = new JRadioButton("No theme image");
....
{
themeScope.add(themeFolders);
themeScope.add(themeSingle);
themeScope.add(themeToponly);
themeScope.add(themeNone);
.... then put them on a panel further down the line....
{
add(themeFolders);
add("br", themeSingle);
add("br", themeToponly);
add("br", themeNone);
}
}
And finally, the "fix" upon loading an older project: if (savedVersion < 41) {
System.out.println("Project file prior to Jupiter 41");
if (!(Boolean) vars.get("useThemes")) {
vars.put("themeFolders", Boolean.FALSE);
vars.put("themeSingle", Boolean.FALSE);
vars.put("themeToponly", Boolean.FALSE);
vars.put("themeNone", Boolean.TRUE);
}
}
My attempts to replicate what I've seen in the "official" Java tutorials simply produce a sea of red in NetBeans, mostly of the "identifier expected" variety.
|
|
|
Posts:
3,822
Registered:
18-Oct-2002
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 16:05
in response to: JeffTucker
|
|
|
The SkinModel is fine, as for the rest:
In Jupiter.java, in the ControlPanel ui setup: {
....
{
ButtonGroup themeScope = new ButtonGroup();
JRadioButton themeFolders = new JRadioButton("Use folder-specific theme images");
JRadioButton themeSingle = new JRadioButton("Use top-level theme image for all folders");
JRadioButton themeToponly = new JRadioButton("Use theme image on top level only");
JRadioButton themeNone = new JRadioButton("No theme image");
// Set actionCommands
themeFolders.setActionCommand("themeFolders");
themeSingle.setActionCommand("themeSingle");
themeToponly.setActionCommand("themeToponly");
themeNone.setActionCommand("themeNone");
themeScope.add(themeFolders);
themeScope.add(themeSingle);
themeScope.add(themeToponly);
themeScope.add(themeNone);
.... then put them on a panel further down the line....
{
add(themeFolders);
add("br", themeSingle);
add("br", themeToponly);
add("br", themeNone);
}
}
And finally, the "fix" upon loading an older project: if (savedVersion < 41) {
System.out.println("Project file prior to Jupiter 41");
if (!(Boolean) vars.get("useThemes")) {
vars.put("themeScope", "themeNone");
}
}
|
|
|
Posts:
8,033
Registered:
31-Jan-2006
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 17:25
in response to: davidekholm
|
|
|
Well, no red in NetBeans, and it compiles. But the result was still wrong. Once again, however, my guessing percentage is pretty good. I don't have a clue why this works, but it does: if (savedVersion < 41) {
System.out.println("Project file prior to Jupiter 41");
if (!(Boolean) vars.get("useThemes")) {
vars.put("themeFolders", Boolean.FALSE);
vars.put("themeNone", Boolean.TRUE);
vars.put("themeScope", "themeNone");
}
}
And yes, all three statements are necessary. If I just set themeNone to TRUE, without also setting themeFolders to FALSE, it doesn't work.
|
|
|
Posts:
8,033
Registered:
31-Jan-2006
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 17:33
in response to: JeffTucker
|
|
|
In fact, the "put" for themeScope isn't necessary, but resetting all of the buttons is, depending upon what's in the saved project. So, this works reliably: if (!(Boolean) vars.get("useThemes")) {
vars.put("themeFolders", Boolean.FALSE);
vars.put("themeSingle", Boolean.FALSE);
vars.put("themeToponly", Boolean.FALSE);
vars.put("themeNone", Boolean.TRUE);
}
That's pretty much where I started. Adding the setActionCommand was the only change needed.
|
|
|
Posts:
3,822
Registered:
18-Oct-2002
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 18:45
in response to: JeffTucker
|
|
|
|
Great that it sorted out!
|
|
|
Posts:
8,033
Registered:
31-Jan-2006
|
|
|
|
Re: Forcing a radio button setting
Posted:
5 Aug 21, 20:49
in response to: davidekholm
|
|
|
|
|
Yes, and in spite of being misdirected by a Swedish trickster!
It's a problem I really needed to crack. It threw me for quite a loop earlier. I rebuilt one of my demo pages, the one for the top level of the Venus demo's. But all of those top level pages use Jupiter to make the page. As you can see from the right.png screenshot, there's no theme image. But reopening the project with the new radio button scheme, it defaulted to making a theme image, and I didn't notice.
Imagine my confusion when I saw what you see in the wrong.png screenshot! I couldn't, for the life of me, figure out where those double titles were coming from. I was utterly mystified, certain that I'd uncovered some bizarre jAlbum bug! But take a look at the screenshot more closely. The second set of album titles is, of course, coming from the theme image itself - notice the first thumbnail on the page. I felt like a moron. 
|
|
|
Posts:
3,822
Registered:
18-Oct-2002
|
|
|
|
Re: Forcing a radio button setting
Posted:
6 Aug 21, 09:34
in response to: JeffTucker
|
|
|
|
|
|
|
Legend
|
|
Forum admins
|
|
Helpful Answer
|
|
Correct Answer
|
|