![swing – What’s one of the simplest ways to deal with JComponents based mostly on Java Knowledge Varieties? swing – What’s one of the simplest ways to deal with JComponents based mostly on Java Knowledge Varieties?](https://geeks-news.com/wp-content/uploads/https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=73d79a89bded)
[ad_1]
I’ve a program which creates a gui to set off APIs, and utilizing Mirror im studying the mandatory parameters of the API and need to create a person enter in order that the person can put together the API earlier than execution.
For instance:
void getAccountInfo(String identify, int id, lengthy customer_id, double balnce, boolean isActive)
What I am attempting to determine is what’s one of the simplest ways to dynamically show the JComponent inputs based mostly on the datatypes of the API parameters.
I created the next swap statment which is mainly studying the datatype of every variable and creates a special JComponent, however I came upon that this may trigger some points:
swap(entry.getValue().getSimpleName()){
case "int":
//SpinnerModel intSpinnerModel = new SpinnerNumberModel(0, Integer.MIN_VALUE, Integer.MAX_VALUE, 1);
inputComponent = new JSpinner();
break;
case "lengthy":
//SpinnerModel longSpinnerModel = new SpinnerNumberModel(0, Lengthy.MIN_VALUE, Lengthy.MAX_VALUE, 1);
inputComponent = new JSpinner();
break;
case "double":
//SpinnerModel doubleSpinnerModel = new SpinnerNumberModel(0.00, -1.0e100, 1.0e100, 0.01);
inputComponent = new JSpinner();
break;
case "boolean":
inputComponent = new JComboBox<String>(new String[] { null, "true", "false" });
break;
case "String":
inputComponent = new JTextField();
break;
}
For now this works nice however it would trigger points sooner or later:
- In case of
char
I can’t add a JTextField as a result of the person would possibly go greater than 1 character - In case of numeric values I can’t use a JSpinner as a result of if
int
then I shouldn’t permit decimals, iffloat
ordouble
I shouldn’t permit greater than 2 decimals. I attempted utilizingSpinnerModel
however looks like just isn’t working correctly.
Is there an alternate method to what I am attempting to realize right here or ought to I simply give attention to fixing the present code! For this I am solely utilizing java.swing
and java.awt
[ad_2]