How to add lists to SelectBox in libgdx - java

I have a selectbox in libgdx , I am trying to add a list of values to it . Is the a way i can add the list such as selectbox.addAll(list1) ?

Due to SelectBox reference the method you are looking for is
public void setItems(T... newItems)
You can use it for example like this:
SelectBox.SelectBoxStyle boxStyle = new SelectBox.SelectBoxStyle();
//creating boxStyle...
String[] values = new String[]{"value1", "value2", "value3", "value4"};
SelectBox<String> selectBox = new SelectBox<String>(boxStyle);
selectBox.setItems(values);
Of course instead of creating the style manually you can use Skin with predefined .json file for this purpose

Related

How can I send the elements of the tableview to another tableview?

Basically what I'm trying to do is, I create a type object with a name and attribute names (I tried to collect those attribute names in a tableview). Then I create items by selecting those types I created before. The Item object i create has its name,type and attribute names. What I want is, when I'm creating an item, I select a type. When I select that type, I want the tableview in item creating page to show selected types attribute names.item creating page is something like that
I tried something like this. Those are my initialize method and creatType methods.
any suggestions?
ObservableList<Types> list2 = FXCollections.observableArrayList();
ObservableList<Items> list3 = FXCollections.observableArrayList();
public void initialize(URL url, ResourceBundle resourceBundle) {
typeAttributesNames.setCellValueFactory(new PropertyValueFactory<Types, String>("typeAttributesNames"));
this.itemAttrValue.setCellValueFactory(new PropertyValueFactory<Items,String>("attributeValues"));
typeAttrNameColumn.setCellValueFactory(new PropertyValueFactory<Types,String>("typeAttributesNames2"));
attrNameTableView.setItems(list2);
itemsAttrTableView.setItems(list3);
}
public void createType(){
ObservableList<Types> typesObservableList=list2;
Types types= new Types(typesTextField.getText(),typesObservableList);
types.getTypesTitledPane().setText(typesTextField.getText());
typeTitledPaneVbox.getChildren().addAll(types.getTypesTitledPane());
typeNameComboBox.getItems().addAll(typesTextField.getText());
Types.typesArrayList.add(types);
typesTextField.clear();
typeNameComboBox.setOnAction(e ->
typeAttrTableView.setItems(typesObservableList));
attrNameTableView.getItems().clear();
}

Using Json Data in hashmap , For exact reference to json Array data .And using it as a string array for numberpicker

I am working on android application and using number picker for displaying data.
I have this json as a string:
{"Acura": ["CL", "ILX", "Integra", "Legend", "MDX", "NSX", "RDX", "RL", "RLX", "RSX", "SLX", "TL", "TLX", "TSX", "Vigor", "ZDX", "Other Acura Models"],
"Alfa": ["164", "4C", "8C Competizione", "Giulia", "GTV-6", "Milano", "Spider", "Stelvio", "Other Alfa Romeo Models"],
"AMC": ["Alliance", "Concord", "Eagle", "Encore", "Spirit", "Other AMC Models"],
"Aston": ["DB11", "DB7", "DB9", "DBS", "Lagonda", "Rapide", "Rapide S", "V12 Vantage", "V8 Vantage", "Vanquish"]} .
What I was trying get the object like, Acura, Alfa, AMC, Aston, in single arraylist. I was stuck how to get Acura models in another numberpicker ,
there I need to pass string array of data .
So this was my ambiguous situation.
Now what I need is, I have objects string array so that whenever I pick Acura, the other picker should show Acura models.
If I select Alfa, other picker shows Alfa models. For this I think I need to have hashmap. Still I am unaware how to implement that, if someone can help me out this situation. Thanks.
you need to store your data in a Map<String,List<String>> like this
Type mapType = new TypeToken<Map<String, List<String>>>() {}.getType();
Map<String, List<String>> source = new Gson().fromJson('your_json_string_here', mapType);
and then iterate over it like this :
for (Map.Entry<String, List<String>> entry : source.entrySet()) {
String key = entry.getKey();
List<String> values = entry.getValue();
//Here you can write your code to do whatever you want
}

Scala/Java BsonDocument append not working properly

I am new to scala and I am trying to create a custom BsonDocument. As far as I read in the documentation here, there's this method append(String key, BsonValue value) that calls the put method internally and I am trying to use it.
The problem is that when I append more than two fields, only the last two get appended. For example if I have a code like this:
var doc = new BsonDocument();
val mapAccounts = user.accounts.map(e => new BsonString(e))
doc.append("$set", new BsonDocument("userName", new BsonString(user.userName)))
.append("$set", new BsonDocument("color", new BsonString(user.color)))
.append("$addToSet", new BsonDocument("accounts", new BsonDocument("$each", new BsonArray(mapAccounts.toList.asJava))))
println(s"The Bson user is $doc")
In this case, I get an output like:
The Bson user is { "$set" : { "color" : "teal" }, "$addToSet" : { "accounts" : { "$each" : ["1"] } } }
As you can see, the userName is not being appended. And it repeats for the last two appended elements if I change the order.
I already tried to use put directly but still got the same result. Also tried to append individually like doc = doc.append(...) and still the same.
What am I missing here?
You cannot have two $set (a BSONDocument is basically a key-value mapping, and appending the same key again just resets it, in the same way a Map.put would).
What you want is
"$set" : {
"color" : "teal",
"username": "Jim"
}
You have to use $set key with both values as the BsonDocument is backed by Map.
doc.append("$set", new BsonDocument("userName", new BsonString(user.userName)).append("color", new BsonString(user.color)))
.append("$addToSet", new BsonDocument("accounts", new BsonDocument("$each", new BsonArray(mapAccounts.toList.asJava))))

JTable with data from properties file

I have simple JTable object with 2 columns. I want to put here values from file.properties but I don't know how do this.
For example file.properties looks like:
some1.text1=Text1
some1.text2=Text2
some2.text1=Text_1
some2.text2=Text_2
And now I want to add these data to TableModel like this(it's example from swing):
Object rowData[][] = { { some1.text1, some2.text1 }, ... };
How can I do this?
You would NOT create a 2 dimensional array since you may not know how many properties you have.
Instead you would create one row of data for each property and then add the row to the DefaultTableModel. The basic logic would be something like:
String columnNames = { "Column1", "Column2" };
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
for (each property pair)
{
Vector<String> row = new Vector<String>(2);
row.addElement( get first value );
row.addElement( get second value );
model.addRow( row );
}
JTable table = new JTable( model );
I found one way to do this using 'new Property()'
This read my file.propertieswell but now I'm interesting something else. How can I read my file in other way, for example my file.property looks like:
some.1.name=...
some.1.value=...
some.2.name=...
some.2.value=...
I can read each of them like this
#ResourceBundleBean(key="some.1.name")
private String some_1_name;
#ResourceBundleBean(key="some.1.value")
private String some_1_value;
etc...
But if is there possibility to use only one String field for for name and value(Value is String too) OR only 1 String field to get each property some.1. some.2. etc and get from this field name and value?
For example if my file.properties will have many item only with name/value some like:
some.1.name=...
some.1.value=...
...
some.200.name=...
some.200.value=...
I do not want to create 200 fields to do this. Is it possible?
Or if it is not possible how can I read arrays from property?
Instead of upper properties make some like this:
some.[1].name=n1
some.[1].value=v1
...
some.[200].name=n200
some.[200].value=v200
And how can I read this array to use it for output some like:
n1 - v1
...
n200 - v200

How to use EXT-GWT ComboBox

How do I use ComboBox in EXT-GWT with static data.
For example I just want to hard code (for demo purposes) list of First Names and display it to the user.
I don't want to use any dummy objects that they are using in their samples. Where can I find simple example with Strings?
Here is the code I use in my project:
SimpleComboBox combo = new SimpleComboBox();
combo.add("One");
combo.add("Two");
combo.add("Three");
combo.setSimpleValue("Two");
Maksim,
I am not sure whether it helps you or not. It was based on the GWT-EXT for combobox.
As I remember that, it wraps the String[] with SimpleStore object.
//create a Store using local array data
final Store store = new SimpleStore(new String[]{"abbr", "state", "nick"}, getStates());
store.load();
final ComboBox cb = new ComboBox();
cb.setForceSelection(true);
cb.setMinChars(1);
cb.setFieldLabel("State");
cb.setStore(store);
cb.setDisplayField("state");
cb.setMode(ComboBox.LOCAL);
cb.setTriggerAction(ComboBox.ALL);
cb.setEmptyText("Enter state");
cb.setLoadingText("Searching...");
cb.setTypeAhead(true);
cb.setSelectOnFocus(true);
cb.setWidth(200);
I hope it helps.
Tiger
ps) Did you try this example ?
// create store
ListStore<String> store = new ListStore<String>();
store.add( Arrays.asList( new String[]{"A","B","C"}));
ComboBox cb = new ComboBox();
cb.setStore(store);

Categories

Resources