how to setvalue in combobox from database in javafx - javafx

I have one combo in javaFX that is populated with categoryData
#FXML
private ComboBox<categoryData> comboCategory;
comboboxCategory suppose to fetch data from database when i clicked the edit button, but i get an error with this line
comboCategory.getSelectionModel().select(rs.getString("category"));
here is my error:
method selectionModel.select(int) is not applicable
string cannot be converted to int
method selectionModel.select(categoryData) is not applicacle
string cannot be converted to categoryData
please help me i am searching for this since yesterday but i got nothing. thank you for your response.

I FOUND THE ANSWER OF MY QUESTION
Predicate<categoryData> matcher = data1 -> (data1.getCategory()).equals(rs.getString("category");
Optional<categoryData> opt = data.stream().filter(matcher).findAny();
comboCategory.setValue(opt.get());

Related

Clearing tableview by clicking button from other fxml

I have an ordersFXML which has a tableview (ordersTable). When you click a button that pops up another paymentsFXML (payments)which contains a payButton. After clicking payButton paymentsFXML closes.
My problem is here.
I want ordersTable to be cleared up, emptied as soon as payButton is clicked.
Is there any way to do it?
Here is my code below.
OrdersFXMLController.java
#FXML
private TableView<Orders> tableOrders;
#FXML
public void clearAll(){
tableOrders.setItems(null);
}
PaymentsFXMLController.java
#FXML
private void finilizePayment(ActionEvent event){
// some code here
closeButtonAction();
}
#FXML
private void closeButtonAction(){
FXMLLoader loader = new FXMLLoader();
OrdersFXMLController orderController = (OrdersFXMLController)loader.getController();
orderController.clearAll();
}
And, here is the error code:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Thanks in advance.
There is always a way; in fact, you have a few different options for this.
Since you did not post any of your code, I am going to make some assumptions with this answer and just provide possible concepts, not necessarily the best way to do it; it all depends on how you've implemented your data model and such.
One way is to include a public method in your ordersFXML controller (which I'll refer to as ordersController) that allows you to clear the table from your paymentsController class:
public void clearOrdersTable() {
tableOrders.setItems(null);
}
After doing that, you will need to pass a reference for ordersController to your paymentsController class when calling its constructor. If creating the controller from your ordersController class:
PaymentsController paymentsController = new PaymentsController(this);
At this point, you have the ability to access your ordersController from your paymentsController and you've set up a method you can use to clear the list of orders in your TableView. Now you just need to call that method after processing the payment:
ordersController.clearOrdersTable();
Again, some assumptions are made. If you are populating your orders table with an actual underlying list (which you should be), you should clear that list instead of setting the table's items to null.
Without seeing your code, though, this may not work for you but will hopefully give you a good starting point for your own troubleshooting.
For further reading and to help yourself grasp the concept of passing values between different controllers, check out jewelsea's excellent answer to this question: Passing Parameters JavaFX FXML.

Binding int to Label in javaFX [duplicate]

This question already has an answer here:
Is it possible to bind a StringProperty to a POJO's String in JavaFX?
(1 answer)
Closed 6 years ago.
I'm trying to bind a intobject to a Label in javaFX and i don't want to change the type in the model to a IntegerProperty. I tried as
mainActionLabel.setText(myintvar);
mainActionLabel.textProperty().bind(new SimpleIntegerProperty(myintvar.asString());
but the value only updates if i close and open the gui again, so i guess the bind is not really working since i imagine it updating with the setText method.
Is there another way to properly bind it?
Edit: I just tried to remove the
mainActionLabel.setText(myintvar);
line but the problem persist as before: the is initialized correctly, but does not update in real time. Only if I close the window and reopen it.
Use asString for the IntegerProperty:
IntegerProperty property = new SimpleIntegerProperty();
Button btn = new Button("increment");
btn.setOnAction((ActionEvent event) -> {
property.set(property.get()+1);
});
Label label = new Label();
label.textProperty().bind(property.asString());
If you are unwilling to change the model data to IntegerProperty, you will not be able to take advantage of property bindings.
You will have to implement the synchronization yourself using listeners and in the getters and setters of your model.

Why does TableCloumn<S,T> take 2 Elements?

The JavaDoc says:
Type Parameters:
S - The type of the TableView generic type (i.e. S == TableView<S>)
T - The type of the content in all cells in this TableColumn.
What does "generic type" mean in this context? If the content is a String, the generic type would also be a string, would it not?
I'm trying to compile the following code taking a String:
TableColumn col = new TableColumn<?, String>();
public void append(String str) {
col.add(str);
}
Why am I not able to do this?
S is your domain object
T is a value of the domain object you want to
show in that column.
Please have a look at the Javadoc for these kind of questions:
http://docs.oracle.com/javafx/2/api/javafx/scene/control/TableView.html

Renaming a button from a string

I am trying to rename a button from a string. Sounds simple enough? Well I have scowered the internet and tried many things however I keep coming up with the same errors.
I have 2 forms and one class file. I am using object orientation to pass a string from a textbox to form1 where upon the "button1.Text" can be change passing it through my "Reference class" (I don't think it can be done any other way)
private void button1_Click_1(object sender, EventArgs e)
{
Refclass Ref = new Refclass();
String but1 = Ref.but1;
String btn = "button1"; this.Controls[btn].Text = but1;
}
I am sure this is probably wrong but I hope by this might be able to understand what I am trying to do. I am calling a string from the "Ref" class and calling the string "hell"
Needless to say I am either getting a debugging error and totally crashing visual studio or I get an error saying "Object reference not set to an instance of an object."
I know I am going wrong somewhere does anyone know where? Thank you.
there is no need of create the object for class.if your class in same assembly.just call like this.
button1.text=ref.but1;
where but1 is a const string in that class.

Get selectedItem data value from Treeview in actionscript flex

Main Thread (Suspended: ReferenceError: Error #1081: Property #data not found on Object and there is no default value.)
Hi All i am getting the above error when calling:
private function openStrm(event:Event):void {
if (event) {
getThingsInStrm(event.currentTarget.selectedItem.#data);
}
}
There is definitely a data property in the selectedItem i can see it in the watch/Variables window while debugging. I am not an as developer so i am a bit lost. Any help is appreciated! thanks
The selectedItem is usually an object form your dataProvider. Does that object contain a property named data?
Show us your actual data, and perhaps a runnable sample and maybe we can help more.

Resources