I'm trying to add a RadioGroupFieldEditor in an Eclipse RCP application I'm developing, but seem unable to do two key things:
set the value for the radio button (i.e. when the dialog/window is opened, I'd like to for example set the default to "button1")
get the current value of the selected radio button (i.e. what has been selected by the user, or if nothing has been set, the default value set above).
The code I'm using is as follows:
String[][] radioButtonOptions = new String[][] { { "Button1" "button1" },
{ "Button2" "button2" } };
RadioGroupFieldEditor radioButtonGroup
= new RadioGroupFieldEditor("PrefValue", "Choose Button1 or Button2", 2,
radioButtonOptions, parent, true)
I have a fireValueChanged() method, which I could use to set another String variable with the value (when the user makes a choice), but this just seems messy. It also won't allow me to set the default value...
I suspect I'm missing something significant! Should there be get/set methods for the above?
Since this control is operating on preferences, you can set the default value in your preference initializer.
To get the value of the control, you could gt the actual radio control via the getRadioBoxControl(Composite) method and query that object. Not the cleanest way, but it does work adequately.
Related
I have a CheckComboBox that I populate with data I grab from a website with the following method.
public void getCompanies() {
// This method is called every time the user types a letter in the URLText box.
// Grab data from the website and add the data to a list.
HTMLParser p = new HTMLParser(URLText.getText());
List<String> a = p.GetCompanyNames();
// Remove old data so new data can be added.
dropdownMultiple.getItems().remove(0, dropdownMultiple.getItems().size());
for(String element : a) {
dropdownMultiple.getItems().add(element);
}
}
This works just fine but I would like to have the CheckComboBox open the dropdown whenever this method is called. I have a textbox overlayed on top of the CheckComboBox so the user can't click on it. Ultimately I want it to look like an autocomplete dropdown that will dropdown whenever the user types in the text box.
In other words, how can I activate the dropdown event of the CheckComboBox without having the user click on it?
I'm assuming you're talking about org.controlsfx.control.CheckComboBox. Unfortunately, it does not appear the library provides a way to programatically show the popup. But if you don't mind relying on implementation details there is a way to do what you want.
The CheckComboBox's skin uses a JavaFX ComboBox internally. This latter class has a method named show that can be used to manually display the popup. You can get access to this ComboBox via a call to Node.lookup(String).
CheckComboBox<String> box = new CheckComboBox<>();
((ComboBox<?>) box.lookup(".combo-box")).show();
Note: This requires that the CheckComboBox is being displayed in a window.
As a reminder, this deals with implementation details and can therefore break without notice. From looking at the source code this should work for both ControlsFX 8.40.14 and 9.0.0.
I'm using JavaFX for my application's GUI. I want to implement a validation method for all the textfields inside the sign up window. I want to check them all and than, whether they are true or false, I want to use a mark to show the user what field is incorrect. I also want to be able to show a small message box when I hover the mouse pointer over those marks.
Simple way is to create HBox , put TextField,Label in there ,label will be Bound on the textProperty/ or do it with listener
txtField.textProperty().addListener((v, oldValue, newValue) -> {
//code here if valid, set label visible false, else set label visible true(red image crossed or whatever)
});
, when value changes it will check if that is ACCEPTABLE/FAILED state , for instance empty box.States will be changed on property change , use array of your hboxes to check if they are valid or invalid at the time , you can check this based on visibility of Label or internal boolean state value.
For the hover over part , use Tooltip on label.
If you want to go lazyer way , take a look at controlsfx validation it will take care of graphics for you.And its already embedded in its component.Just create validation process
Good beginner reference might be newboston videos so you understand concept.In javafx you gonna use property binding ,listeners etc often , get familiar with them as you cant avoid it.
https://www.youtube.com/watch?v=s8GomyEOA8w
https://www.youtube.com/watch?v=6Zi2L0kHSx4
Since you've given no code I can't give you answer that involves actual coding, because I've got no way of knowing whether or not what I give you will be viable or conflict etc..
In regards to the validation that depends entirely on how your accessing a username/password to compare it to what the user has entered and with out knowing how you're thinking of doing it I cannot give you a good answer.
There are quite a few options to display your red x, you could draw it internally etc..
But the easiest is probably going to be creating an image and importing it to your project, you can set a label next to your JTextField and have the picture set to that lable. Once the user inputs the username/password if either or both are incorrect you could have a method that would set the label to be visible.
The message box is as simple as a tooltip that you could also place on the label which would tell the user that the information they entered is wrong.
Using JavaFX 8 with FXML.
I have 2 sets of Radio Buttons; Set 1: A, B, C, D Set 2: X, Y
What I am looking for is
Make sure user checks one Radio button from each set before hitting submit, and prompt the user if they didn't.
Based on the selection, I will write certain data to an array.
For example, for combination A and Y selection, write " some text " to AYcombo array. For combination B and Y write "some text" to BYCombo array. And so forth.
This can easily be done by using bindings and properties. A ToggleGroup defines the selected toggle as a property (selectedToggleProperty) and you can create a BooleanBinding based on this properties:
BooleanBinding binding = groupA.selectedToggleProperty().isNotNull().and(groupB.selectedToggleProperty().isNotNull());
Now you can bind the disable property of the button to this binding:
button.disableProperty().bind(binding.not());
To define the data you can add a listener to the binding (that will be called whenever anything in the binding has changed):
binding.addListener(e -> {
if(binding.getValue()) {
// calculate and set data
}
})
as I mentioned in a post before, I'm porting my program to Java, to make it available for Mac OS and Linux users.
At the start of the program, I'd like to check if adb is installed to the system using this code:
private void checkADBExists()
// Checks if adb binaries exist and sets jTogglebutton1 correspondingly...
{
File adb = new File("/usr/bin/adb");
if (!adb.exists())
{
jToggleButton1.isSelected();
} else {
jToggleButton1.isSelected()= false;
}
}
Here's my problem:
If the file doesn't exist, the JToggleButton isn't selected, even though it should be and I get an error deselecting it.
Any help is much appreciated.
Thanks in advance,
Beats
Many of Swing's core components follow a simple getter/setter pattern.
That is, you can "get" a property value and "set" a property value (note, not all getters have a corresponding setter though).
In the case of a boolean property, the convention is to use "is" instead of "get", it just rolls off the tongue better.
So, in your case, all you are doing is getting the value if the selected property, not really what you want to do.
Instead use jToggleButton1.setSelected(true) or jToggleButton1.setSelected(false) based on your needs
You might like to take a look at How to Use Buttons, Check Boxes, and Radio Buttons for some more details
JToggleButton().isSelected() return a value not a variable. By JToggleButton().isSelected() = false, you are trying to assign a value to a value, it doesn't make sense, much like writing a statement 2 = 2;. use JToggleButton.setSelected(true) to set the toggle button as selected and JToggleButton.setSelected(false) to deselect.
I'm using a DatePicker (org.apache.wicket.extensions.yui.calendar.DatePicker — Javadoc) in a form. The form consists of two fields. The first field is a dropdown, and the second changes dynamically based on the first. If "text" is selected, a textbox comes up; if "list" is selected, a dropdown menu comes up; and if "date" is selected, a date picker and associated field come up.
Here's a simplified version of my current code:
DateTextField dateField = new DateTextField("dateField", // ...
DatePicker datePicker = new DatePicker();
dateField.add(datePicker);
fieldOne.add(new OnChangeAjaxBehavior() {
protected void onUpdate(AjaxRequestTarget target) {
if (fieldOne.equalsIgnoreCase("list"))
{
dateField.setVisible(false);
// datePicker.setVisible(false); // This line is impossible
listField.setVisible(true);
textField.setVisible(false);
}
else if { /* similar visibility settings for dates and text */ }
}
});
The form currently works properly for changing to the date picker. The problem arises when date is selected and then the user selects something else. The date field disappears, but the date picker remains on the screen. Unfortunately, it doesn't seem to have a setVisible() method, or any equivalent. In fact, it's not even a true Wicket Component.
How can I make them appear/disappear together? If I can't set the picker's visibility directly, can I tie it to the field's visibility somehow?
By far the easiest yet still fairly maintainable solution is to group the components you want to hide together in a WebMarkupContainer. In the markup you'll probably want to use a <div> element for the container, but this depends on what you want to hide. (Sometimes the markup itself prevents you from using this method but let's hope your markup doesn't. :))
Then just change the visibility of the container.
A good idea with AjaxListeners also is to call .setOutputMarkupId(true) on the Component you want to handle. Otherwise you are possibly not able to "locate" it.
In case you are not rendering it on load, but intend to add the component later, I think you should also call setOutputMarkupPlaceholderTag(true).
This helped me several times...