JAVAFX: How to set a MouseEvent leftclick action on a cell with data in TableViewHow to convert an Array to a Set in JavaWhy this class should implement java.io.Serializable when I using hibernate?OGNL setValue target is nullproblem in setting scrollpane for canvasType mismatch in key from map: expected .. Text, received … LongWritableClone a Singleton objectParameters is passing default value in TestNGJavaFX TableView doesn't show the contentSpring MVC form validation does't work for nested complex typesGoogle Play License Verification Library with flutter
Does git delete empty folders?
Sleeping solo in a double sleeping bag
How could China have extradited people for political reason under the extradition law it wanted to pass in Hong Kong?
"Silverware", "Tableware", and "Dishes"
How many spells can a level 1 wizard learn?
What can I do to keep a threaded bolt from falling out of it’s slot
How does the Saturn V Dynamic Test Stand work?
Earliest evidence of objects intended for future archaeologists?
Why doesn't mathematics collapse down, even though humans quite often make mistakes in their proofs?
Best Practice: dependency on data model names
Can I submit a paper under an alias so as to avoid trouble in my country?
Do predators tend to have vertical slit pupils versus horizontal for prey animals?
Are there any OR challenges that are similar to kaggle's competitions?
In xXx, is Xander Cage's 10th vehicle a specific reference to another franchise?
How can I describe being temporarily stupid?
What happened after the end of the Truman Show?
Can a Beast Master ranger choose a swarm as an animal companion?
Why would the President need briefings on UFOs?
Is "stainless" a bulk or a surface property of stainless steel?
Nuclear decay triggers
How do I intentionally fragment a SQL Server Index?
What is the latest version of SQL Server native client that is compatible with Sql Server 2008 r2
Church Booleans
Writing/buying Seforim rather than Sefer Torah
JAVAFX: How to set a MouseEvent leftclick action on a cell with data in TableView
How to convert an Array to a Set in JavaWhy this class should implement java.io.Serializable when I using hibernate?OGNL setValue target is nullproblem in setting scrollpane for canvasType mismatch in key from map: expected .. Text, received … LongWritableClone a Singleton objectParameters is passing default value in TestNGJavaFX TableView doesn't show the contentSpring MVC form validation does't work for nested complex typesGoogle Play License Verification Library with flutter
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am a beginner Java student who would like to call himself a developer one day. I've been studying stackoverflow for a while, found many solutions and useful informations. This is my first post so please don't be too harsh on me. I was trying to find solution to my problem by myself but failed.
I am trying to make my TableView cells with data react on MouseEvent leftclick (I want it to open different Image in Imageviewer below the table with data when I leftclick on the specific TableView cell).
This is for a Windows App.
My Main Controller:
package main;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class SpinChartsController implements Initializable
@FXML
MenuItem close;
@FXML
TableView<TableValues> tableView;
@FXML
TableColumn<TableValues, String> btn;
@FXML
TableColumn<TableValues, String> sBvsBtnLimp;
@FXML
TableColumn<TableValues, String> sBvsBtn;
@FXML
TableColumn<TableValues, String> sBvsBB;
@FXML
TableColumn<TableValues, String> bBvsBtn;
@FXML
TableColumn<TableValues, String> bBvsBtnLimp;
@FXML
TableColumn<TableValues, String> bBvs2pp;
@FXML
TableColumn<TableValues, String> bBvs2ppLimp;
@FXML
TableColumn<TableValues, String> bBvsSB;
@FXML
TableColumn<TableValues, String> bBvsSBLimp;
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
//ustawia kolumny w tabeli
btn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("Btn"));
sBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("sBvsBtnLimp"));
sBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBtn"));
sBvsBB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBB"));
bBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtn"));
bBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtnLimp"));
bBvs2pp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2pp"));
bBvs2ppLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2ppLimp"));
bBvsSB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSB"));
bBvsSBLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSBLimp"));
//dodanie danych do tabeli (dodawane wierszami)
tableView.setItems(getDataForTheTable());
//metoda dodajaca dane do tabeli wierszami
public ObservableList<TableValues> getDataForTheTable()
ObservableList<TableValues> rowsValues = FXCollections.observableArrayList();
rowsValues.add(new TableValues("", "", "vs AI", "", "vs AI", "",
"vs AI", "", "vs AI", ""));
rowsValues.add(new TableValues("25+", "", "", "", "", "",
"", "", "25+", "25+"));
rowsValues.add(new TableValues("20-25", "20+", "20+", "20+", "20+", "20+",
"20+", "20+", "20-25", "20-25"));
rowsValues.add(new TableValues("16-20", "16-20", "16-20", "16-20", "16-20", "16-20",
"16-20", "16-20", "16-20", "16-20"));
rowsValues.add(new TableValues("13-16", "13-16", "13-16", "13-16", "13-16", "13-16",
"13-16", "13-16", "13-16", "13-16"));
rowsValues.add(new TableValues("10-13", "10-13", "10-13", "10-13", "10-13", "10-13",
"10-13", "10-13", "10-13", "10-13"));
rowsValues.add(new TableValues("9", "8-10", "", "8-10", "8-10", "8-10",
"8-10", "8-10", "8-10", "8-10"));
rowsValues.add(new TableValues("8", "6-8", "", "6-8", "vs 3x 20-25", "",
"", "", "vs 2.5x-3x 20-25", "6-8"));
rowsValues.add(new TableValues("<8", "", "", "4-6", "", "",
"", "", "", "4-6"));
rowsValues.add(new TableValues("", "", "", "", "", "",
"", "", "", ""));
rowsValues.add(new TableValues("ODDS", "", "", "", "", "",
"", "", "", ""));
return rowsValues;
public void closeProgram()
Platform.exit();
System.exit(0);
My TableValues class:
package main;
import javafx.beans.property.SimpleStringProperty;
public class TableValues
//uzywam SimpleStringProperty do TableView bo ma listenery i moge potem z tym cos zrobic
private SimpleStringProperty Btn;
private SimpleStringProperty SBvsBtnLimp;
private SimpleStringProperty SBvsBtn;
private SimpleStringProperty SBvsBB;
private SimpleStringProperty BBvsBtn;
private SimpleStringProperty BBvsBtnLimp;
private SimpleStringProperty BBvs2pp;
private SimpleStringProperty BBvs2ppLimp;
private SimpleStringProperty BBvsSB;
private SimpleStringProperty BBvsSBLimp;
//taki konstruktor by bylo latwiej, beda podawane Stringi a on bedzie sobie sam zamienial
public TableValues(String btn, String SBvsBtnLimp, String SBvsBtn, String SBvsBB, String BBvsBtn,
String BBvsBtnLimp, String BBvs2pp, String BBvs2ppLimp, String BBvsSB, String BBvsSBLimp)
this.Btn = new SimpleStringProperty(btn);
this.SBvsBtnLimp = new SimpleStringProperty(SBvsBtnLimp);
this.SBvsBtn = new SimpleStringProperty(SBvsBtn);
this.SBvsBB = new SimpleStringProperty(SBvsBB);
this.BBvsBtn = new SimpleStringProperty(BBvsBtn);
this.BBvsBtnLimp = new SimpleStringProperty(BBvsBtnLimp);
this.BBvs2pp = new SimpleStringProperty(BBvs2pp);
this.BBvs2ppLimp = new SimpleStringProperty(BBvs2ppLimp);
this.BBvsSB = new SimpleStringProperty(BBvsSB);
this.BBvsSBLimp = new SimpleStringProperty(BBvsSBLimp);
public String getBtn()
return Btn.get();
public void setBtn(String btn)
this.Btn.set(btn);
public String getSBvsBtnLimp()
return SBvsBtnLimp.get();
public void setSBvsBtnLimp(String SBvsBTNLimp)
this.SBvsBtnLimp.set(SBvsBTNLimp);
public String getSBvsBtn()
return SBvsBtn.get();
public void setSBvsBtn(String SBvsBtn)
this.SBvsBtn.set(SBvsBtn);
public String getSBvsBB()
return SBvsBB.get();
public void setSBvsBB(String SBvsBB)
this.SBvsBB.set(SBvsBB);
public String getBBvsBtn()
return BBvsBtn.get();
public void setBBvsBtn(String BBvsBtn)
this.BBvsBtn.set(BBvsBtn);
public String getBBvsBtnLimp()
return BBvsBtnLimp.get();
public void setBBvsBtnLimp(String BBvsBtnLimp)
this.BBvsBtnLimp.set(BBvsBtnLimp);
public String getBBvs2pp()
return BBvs2pp.get();
public void setBBvs2pp(String BBvs2pp)
this.BBvs2pp.set(BBvs2pp);
public String getBBvs2ppLimp()
return BBvs2ppLimp.get();
public void setBBvs2ppLimp(String BBvs2ppLimp)
this.BBvs2ppLimp.set(BBvs2ppLimp);
public String getBBvsSB()
return BBvsSB.get();
public void setBBvsSB(String BBvsSB)
this.BBvsSB.set(BBvsSB);
public String getBBvsSBLimp()
return BBvsSBLimp.get();
public void setBBvsSBLimp(String BBvsSBLimp)
this.BBvsSBLimp.set(BBvsSBLimp);
My fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0"
prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="main.SpinChartsController">
<children>
<MenuBar StackPane.alignment="TOP_LEFT">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="close" mnemonicParsing="false" onAction="#closeProgram" text="Close"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About"/>
</items>
</Menu>
</menus>
</MenuBar>
<TableView fx:id="tableView" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="331.0" prefWidth="884.0"
StackPane.alignment="TOP_LEFT">
<columns>
<TableColumn fx:id="btn" prefWidth="67.99999463558197" sortable="false" text="BTN"/>
<TableColumn fx:id="sBvsBtnLimp" prefWidth="102.40003204345703" sortable="false" text="SB vs BTN Limp"/>
<TableColumn fx:id="sBvsBtn" prefWidth="76.00001525878906" sortable="false" text="SB vs BTN"/>
<TableColumn fx:id="sBvsBB" prefWidth="72.79998779296875" sortable="false" text="SB vs BB"/>
<TableColumn fx:id="bBvsBtn" prefWidth="84.0" sortable="false" text="BB vs BTN"/>
<TableColumn fx:id="bBvsBtnLimp" prefWidth="102.4000244140625" sortable="false" text="BB vs BTN Limp"/>
<TableColumn fx:id="bBvs2pp" prefWidth="84.80001831054688" sortable="false" text="BB vs 2pp"/>
<TableColumn fx:id="bBvs2ppLimp" prefWidth="101.5999755859375" sortable="false" text="BB vs 2pp Limp"/>
<TableColumn fx:id="bBvsSB" prefWidth="79.19989013671875" sortable="false" text="BB vs SB"/>
<TableColumn fx:id="bBvsSBLimp" prefWidth="108.800048828125" sortable="false" text="BB vs SB Limp"/>
</columns>
<StackPane.margin>
<Insets left="50.0" right="50.0" top="50.0"/>
</StackPane.margin>
</TableView>
</children>
</StackPane>
My Main class:
package main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SpinCharts extends Application
@Override
public void start(Stage primaryStage) throws Exception
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("fxmlfiles/spinCharts.fxml"));
StackPane stackPane = loader.load();
Scene scene = new Scene(stackPane);
primaryStage.getIcons().add(new Image("main/diamond.png"));
primaryStage.setOnCloseRequest(event ->
SpinChartsController spinCC = new SpinChartsController();
spinCC.closeProgram();
);
primaryStage.setHeight(800d);
primaryStage.setWidth(1000d);
primaryStage.setMinHeight(600d);
primaryStage.setMinWidth(800d);
primaryStage.setScene(scene);
primaryStage.setTitle("SpinCharts");
primaryStage.show();
public static void main(String[] args)
launch(args);
Please help me with that code I'm missing and be as specific as possible. Sorry if my post-editing is not too good, was doing my best, will improve in the future. Thanks.
java javafx
add a comment |
I am a beginner Java student who would like to call himself a developer one day. I've been studying stackoverflow for a while, found many solutions and useful informations. This is my first post so please don't be too harsh on me. I was trying to find solution to my problem by myself but failed.
I am trying to make my TableView cells with data react on MouseEvent leftclick (I want it to open different Image in Imageviewer below the table with data when I leftclick on the specific TableView cell).
This is for a Windows App.
My Main Controller:
package main;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class SpinChartsController implements Initializable
@FXML
MenuItem close;
@FXML
TableView<TableValues> tableView;
@FXML
TableColumn<TableValues, String> btn;
@FXML
TableColumn<TableValues, String> sBvsBtnLimp;
@FXML
TableColumn<TableValues, String> sBvsBtn;
@FXML
TableColumn<TableValues, String> sBvsBB;
@FXML
TableColumn<TableValues, String> bBvsBtn;
@FXML
TableColumn<TableValues, String> bBvsBtnLimp;
@FXML
TableColumn<TableValues, String> bBvs2pp;
@FXML
TableColumn<TableValues, String> bBvs2ppLimp;
@FXML
TableColumn<TableValues, String> bBvsSB;
@FXML
TableColumn<TableValues, String> bBvsSBLimp;
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
//ustawia kolumny w tabeli
btn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("Btn"));
sBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("sBvsBtnLimp"));
sBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBtn"));
sBvsBB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBB"));
bBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtn"));
bBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtnLimp"));
bBvs2pp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2pp"));
bBvs2ppLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2ppLimp"));
bBvsSB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSB"));
bBvsSBLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSBLimp"));
//dodanie danych do tabeli (dodawane wierszami)
tableView.setItems(getDataForTheTable());
//metoda dodajaca dane do tabeli wierszami
public ObservableList<TableValues> getDataForTheTable()
ObservableList<TableValues> rowsValues = FXCollections.observableArrayList();
rowsValues.add(new TableValues("", "", "vs AI", "", "vs AI", "",
"vs AI", "", "vs AI", ""));
rowsValues.add(new TableValues("25+", "", "", "", "", "",
"", "", "25+", "25+"));
rowsValues.add(new TableValues("20-25", "20+", "20+", "20+", "20+", "20+",
"20+", "20+", "20-25", "20-25"));
rowsValues.add(new TableValues("16-20", "16-20", "16-20", "16-20", "16-20", "16-20",
"16-20", "16-20", "16-20", "16-20"));
rowsValues.add(new TableValues("13-16", "13-16", "13-16", "13-16", "13-16", "13-16",
"13-16", "13-16", "13-16", "13-16"));
rowsValues.add(new TableValues("10-13", "10-13", "10-13", "10-13", "10-13", "10-13",
"10-13", "10-13", "10-13", "10-13"));
rowsValues.add(new TableValues("9", "8-10", "", "8-10", "8-10", "8-10",
"8-10", "8-10", "8-10", "8-10"));
rowsValues.add(new TableValues("8", "6-8", "", "6-8", "vs 3x 20-25", "",
"", "", "vs 2.5x-3x 20-25", "6-8"));
rowsValues.add(new TableValues("<8", "", "", "4-6", "", "",
"", "", "", "4-6"));
rowsValues.add(new TableValues("", "", "", "", "", "",
"", "", "", ""));
rowsValues.add(new TableValues("ODDS", "", "", "", "", "",
"", "", "", ""));
return rowsValues;
public void closeProgram()
Platform.exit();
System.exit(0);
My TableValues class:
package main;
import javafx.beans.property.SimpleStringProperty;
public class TableValues
//uzywam SimpleStringProperty do TableView bo ma listenery i moge potem z tym cos zrobic
private SimpleStringProperty Btn;
private SimpleStringProperty SBvsBtnLimp;
private SimpleStringProperty SBvsBtn;
private SimpleStringProperty SBvsBB;
private SimpleStringProperty BBvsBtn;
private SimpleStringProperty BBvsBtnLimp;
private SimpleStringProperty BBvs2pp;
private SimpleStringProperty BBvs2ppLimp;
private SimpleStringProperty BBvsSB;
private SimpleStringProperty BBvsSBLimp;
//taki konstruktor by bylo latwiej, beda podawane Stringi a on bedzie sobie sam zamienial
public TableValues(String btn, String SBvsBtnLimp, String SBvsBtn, String SBvsBB, String BBvsBtn,
String BBvsBtnLimp, String BBvs2pp, String BBvs2ppLimp, String BBvsSB, String BBvsSBLimp)
this.Btn = new SimpleStringProperty(btn);
this.SBvsBtnLimp = new SimpleStringProperty(SBvsBtnLimp);
this.SBvsBtn = new SimpleStringProperty(SBvsBtn);
this.SBvsBB = new SimpleStringProperty(SBvsBB);
this.BBvsBtn = new SimpleStringProperty(BBvsBtn);
this.BBvsBtnLimp = new SimpleStringProperty(BBvsBtnLimp);
this.BBvs2pp = new SimpleStringProperty(BBvs2pp);
this.BBvs2ppLimp = new SimpleStringProperty(BBvs2ppLimp);
this.BBvsSB = new SimpleStringProperty(BBvsSB);
this.BBvsSBLimp = new SimpleStringProperty(BBvsSBLimp);
public String getBtn()
return Btn.get();
public void setBtn(String btn)
this.Btn.set(btn);
public String getSBvsBtnLimp()
return SBvsBtnLimp.get();
public void setSBvsBtnLimp(String SBvsBTNLimp)
this.SBvsBtnLimp.set(SBvsBTNLimp);
public String getSBvsBtn()
return SBvsBtn.get();
public void setSBvsBtn(String SBvsBtn)
this.SBvsBtn.set(SBvsBtn);
public String getSBvsBB()
return SBvsBB.get();
public void setSBvsBB(String SBvsBB)
this.SBvsBB.set(SBvsBB);
public String getBBvsBtn()
return BBvsBtn.get();
public void setBBvsBtn(String BBvsBtn)
this.BBvsBtn.set(BBvsBtn);
public String getBBvsBtnLimp()
return BBvsBtnLimp.get();
public void setBBvsBtnLimp(String BBvsBtnLimp)
this.BBvsBtnLimp.set(BBvsBtnLimp);
public String getBBvs2pp()
return BBvs2pp.get();
public void setBBvs2pp(String BBvs2pp)
this.BBvs2pp.set(BBvs2pp);
public String getBBvs2ppLimp()
return BBvs2ppLimp.get();
public void setBBvs2ppLimp(String BBvs2ppLimp)
this.BBvs2ppLimp.set(BBvs2ppLimp);
public String getBBvsSB()
return BBvsSB.get();
public void setBBvsSB(String BBvsSB)
this.BBvsSB.set(BBvsSB);
public String getBBvsSBLimp()
return BBvsSBLimp.get();
public void setBBvsSBLimp(String BBvsSBLimp)
this.BBvsSBLimp.set(BBvsSBLimp);
My fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0"
prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="main.SpinChartsController">
<children>
<MenuBar StackPane.alignment="TOP_LEFT">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="close" mnemonicParsing="false" onAction="#closeProgram" text="Close"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About"/>
</items>
</Menu>
</menus>
</MenuBar>
<TableView fx:id="tableView" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="331.0" prefWidth="884.0"
StackPane.alignment="TOP_LEFT">
<columns>
<TableColumn fx:id="btn" prefWidth="67.99999463558197" sortable="false" text="BTN"/>
<TableColumn fx:id="sBvsBtnLimp" prefWidth="102.40003204345703" sortable="false" text="SB vs BTN Limp"/>
<TableColumn fx:id="sBvsBtn" prefWidth="76.00001525878906" sortable="false" text="SB vs BTN"/>
<TableColumn fx:id="sBvsBB" prefWidth="72.79998779296875" sortable="false" text="SB vs BB"/>
<TableColumn fx:id="bBvsBtn" prefWidth="84.0" sortable="false" text="BB vs BTN"/>
<TableColumn fx:id="bBvsBtnLimp" prefWidth="102.4000244140625" sortable="false" text="BB vs BTN Limp"/>
<TableColumn fx:id="bBvs2pp" prefWidth="84.80001831054688" sortable="false" text="BB vs 2pp"/>
<TableColumn fx:id="bBvs2ppLimp" prefWidth="101.5999755859375" sortable="false" text="BB vs 2pp Limp"/>
<TableColumn fx:id="bBvsSB" prefWidth="79.19989013671875" sortable="false" text="BB vs SB"/>
<TableColumn fx:id="bBvsSBLimp" prefWidth="108.800048828125" sortable="false" text="BB vs SB Limp"/>
</columns>
<StackPane.margin>
<Insets left="50.0" right="50.0" top="50.0"/>
</StackPane.margin>
</TableView>
</children>
</StackPane>
My Main class:
package main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SpinCharts extends Application
@Override
public void start(Stage primaryStage) throws Exception
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("fxmlfiles/spinCharts.fxml"));
StackPane stackPane = loader.load();
Scene scene = new Scene(stackPane);
primaryStage.getIcons().add(new Image("main/diamond.png"));
primaryStage.setOnCloseRequest(event ->
SpinChartsController spinCC = new SpinChartsController();
spinCC.closeProgram();
);
primaryStage.setHeight(800d);
primaryStage.setWidth(1000d);
primaryStage.setMinHeight(600d);
primaryStage.setMinWidth(800d);
primaryStage.setScene(scene);
primaryStage.setTitle("SpinCharts");
primaryStage.show();
public static void main(String[] args)
launch(args);
Please help me with that code I'm missing and be as specific as possible. Sorry if my post-editing is not too good, was doing my best, will improve in the future. Thanks.
java javafx
2
you need a custom TableCell implementation that registers the mouseHandler
– kleopatra
Mar 27 at 16:21
1
Ok, I will learn that. Thought I know that naming convention but will take a look at it again. Thank You for the feedback.
– wojciechw
Mar 27 at 18:52
add a comment |
I am a beginner Java student who would like to call himself a developer one day. I've been studying stackoverflow for a while, found many solutions and useful informations. This is my first post so please don't be too harsh on me. I was trying to find solution to my problem by myself but failed.
I am trying to make my TableView cells with data react on MouseEvent leftclick (I want it to open different Image in Imageviewer below the table with data when I leftclick on the specific TableView cell).
This is for a Windows App.
My Main Controller:
package main;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class SpinChartsController implements Initializable
@FXML
MenuItem close;
@FXML
TableView<TableValues> tableView;
@FXML
TableColumn<TableValues, String> btn;
@FXML
TableColumn<TableValues, String> sBvsBtnLimp;
@FXML
TableColumn<TableValues, String> sBvsBtn;
@FXML
TableColumn<TableValues, String> sBvsBB;
@FXML
TableColumn<TableValues, String> bBvsBtn;
@FXML
TableColumn<TableValues, String> bBvsBtnLimp;
@FXML
TableColumn<TableValues, String> bBvs2pp;
@FXML
TableColumn<TableValues, String> bBvs2ppLimp;
@FXML
TableColumn<TableValues, String> bBvsSB;
@FXML
TableColumn<TableValues, String> bBvsSBLimp;
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
//ustawia kolumny w tabeli
btn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("Btn"));
sBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("sBvsBtnLimp"));
sBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBtn"));
sBvsBB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBB"));
bBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtn"));
bBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtnLimp"));
bBvs2pp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2pp"));
bBvs2ppLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2ppLimp"));
bBvsSB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSB"));
bBvsSBLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSBLimp"));
//dodanie danych do tabeli (dodawane wierszami)
tableView.setItems(getDataForTheTable());
//metoda dodajaca dane do tabeli wierszami
public ObservableList<TableValues> getDataForTheTable()
ObservableList<TableValues> rowsValues = FXCollections.observableArrayList();
rowsValues.add(new TableValues("", "", "vs AI", "", "vs AI", "",
"vs AI", "", "vs AI", ""));
rowsValues.add(new TableValues("25+", "", "", "", "", "",
"", "", "25+", "25+"));
rowsValues.add(new TableValues("20-25", "20+", "20+", "20+", "20+", "20+",
"20+", "20+", "20-25", "20-25"));
rowsValues.add(new TableValues("16-20", "16-20", "16-20", "16-20", "16-20", "16-20",
"16-20", "16-20", "16-20", "16-20"));
rowsValues.add(new TableValues("13-16", "13-16", "13-16", "13-16", "13-16", "13-16",
"13-16", "13-16", "13-16", "13-16"));
rowsValues.add(new TableValues("10-13", "10-13", "10-13", "10-13", "10-13", "10-13",
"10-13", "10-13", "10-13", "10-13"));
rowsValues.add(new TableValues("9", "8-10", "", "8-10", "8-10", "8-10",
"8-10", "8-10", "8-10", "8-10"));
rowsValues.add(new TableValues("8", "6-8", "", "6-8", "vs 3x 20-25", "",
"", "", "vs 2.5x-3x 20-25", "6-8"));
rowsValues.add(new TableValues("<8", "", "", "4-6", "", "",
"", "", "", "4-6"));
rowsValues.add(new TableValues("", "", "", "", "", "",
"", "", "", ""));
rowsValues.add(new TableValues("ODDS", "", "", "", "", "",
"", "", "", ""));
return rowsValues;
public void closeProgram()
Platform.exit();
System.exit(0);
My TableValues class:
package main;
import javafx.beans.property.SimpleStringProperty;
public class TableValues
//uzywam SimpleStringProperty do TableView bo ma listenery i moge potem z tym cos zrobic
private SimpleStringProperty Btn;
private SimpleStringProperty SBvsBtnLimp;
private SimpleStringProperty SBvsBtn;
private SimpleStringProperty SBvsBB;
private SimpleStringProperty BBvsBtn;
private SimpleStringProperty BBvsBtnLimp;
private SimpleStringProperty BBvs2pp;
private SimpleStringProperty BBvs2ppLimp;
private SimpleStringProperty BBvsSB;
private SimpleStringProperty BBvsSBLimp;
//taki konstruktor by bylo latwiej, beda podawane Stringi a on bedzie sobie sam zamienial
public TableValues(String btn, String SBvsBtnLimp, String SBvsBtn, String SBvsBB, String BBvsBtn,
String BBvsBtnLimp, String BBvs2pp, String BBvs2ppLimp, String BBvsSB, String BBvsSBLimp)
this.Btn = new SimpleStringProperty(btn);
this.SBvsBtnLimp = new SimpleStringProperty(SBvsBtnLimp);
this.SBvsBtn = new SimpleStringProperty(SBvsBtn);
this.SBvsBB = new SimpleStringProperty(SBvsBB);
this.BBvsBtn = new SimpleStringProperty(BBvsBtn);
this.BBvsBtnLimp = new SimpleStringProperty(BBvsBtnLimp);
this.BBvs2pp = new SimpleStringProperty(BBvs2pp);
this.BBvs2ppLimp = new SimpleStringProperty(BBvs2ppLimp);
this.BBvsSB = new SimpleStringProperty(BBvsSB);
this.BBvsSBLimp = new SimpleStringProperty(BBvsSBLimp);
public String getBtn()
return Btn.get();
public void setBtn(String btn)
this.Btn.set(btn);
public String getSBvsBtnLimp()
return SBvsBtnLimp.get();
public void setSBvsBtnLimp(String SBvsBTNLimp)
this.SBvsBtnLimp.set(SBvsBTNLimp);
public String getSBvsBtn()
return SBvsBtn.get();
public void setSBvsBtn(String SBvsBtn)
this.SBvsBtn.set(SBvsBtn);
public String getSBvsBB()
return SBvsBB.get();
public void setSBvsBB(String SBvsBB)
this.SBvsBB.set(SBvsBB);
public String getBBvsBtn()
return BBvsBtn.get();
public void setBBvsBtn(String BBvsBtn)
this.BBvsBtn.set(BBvsBtn);
public String getBBvsBtnLimp()
return BBvsBtnLimp.get();
public void setBBvsBtnLimp(String BBvsBtnLimp)
this.BBvsBtnLimp.set(BBvsBtnLimp);
public String getBBvs2pp()
return BBvs2pp.get();
public void setBBvs2pp(String BBvs2pp)
this.BBvs2pp.set(BBvs2pp);
public String getBBvs2ppLimp()
return BBvs2ppLimp.get();
public void setBBvs2ppLimp(String BBvs2ppLimp)
this.BBvs2ppLimp.set(BBvs2ppLimp);
public String getBBvsSB()
return BBvsSB.get();
public void setBBvsSB(String BBvsSB)
this.BBvsSB.set(BBvsSB);
public String getBBvsSBLimp()
return BBvsSBLimp.get();
public void setBBvsSBLimp(String BBvsSBLimp)
this.BBvsSBLimp.set(BBvsSBLimp);
My fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0"
prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="main.SpinChartsController">
<children>
<MenuBar StackPane.alignment="TOP_LEFT">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="close" mnemonicParsing="false" onAction="#closeProgram" text="Close"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About"/>
</items>
</Menu>
</menus>
</MenuBar>
<TableView fx:id="tableView" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="331.0" prefWidth="884.0"
StackPane.alignment="TOP_LEFT">
<columns>
<TableColumn fx:id="btn" prefWidth="67.99999463558197" sortable="false" text="BTN"/>
<TableColumn fx:id="sBvsBtnLimp" prefWidth="102.40003204345703" sortable="false" text="SB vs BTN Limp"/>
<TableColumn fx:id="sBvsBtn" prefWidth="76.00001525878906" sortable="false" text="SB vs BTN"/>
<TableColumn fx:id="sBvsBB" prefWidth="72.79998779296875" sortable="false" text="SB vs BB"/>
<TableColumn fx:id="bBvsBtn" prefWidth="84.0" sortable="false" text="BB vs BTN"/>
<TableColumn fx:id="bBvsBtnLimp" prefWidth="102.4000244140625" sortable="false" text="BB vs BTN Limp"/>
<TableColumn fx:id="bBvs2pp" prefWidth="84.80001831054688" sortable="false" text="BB vs 2pp"/>
<TableColumn fx:id="bBvs2ppLimp" prefWidth="101.5999755859375" sortable="false" text="BB vs 2pp Limp"/>
<TableColumn fx:id="bBvsSB" prefWidth="79.19989013671875" sortable="false" text="BB vs SB"/>
<TableColumn fx:id="bBvsSBLimp" prefWidth="108.800048828125" sortable="false" text="BB vs SB Limp"/>
</columns>
<StackPane.margin>
<Insets left="50.0" right="50.0" top="50.0"/>
</StackPane.margin>
</TableView>
</children>
</StackPane>
My Main class:
package main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SpinCharts extends Application
@Override
public void start(Stage primaryStage) throws Exception
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("fxmlfiles/spinCharts.fxml"));
StackPane stackPane = loader.load();
Scene scene = new Scene(stackPane);
primaryStage.getIcons().add(new Image("main/diamond.png"));
primaryStage.setOnCloseRequest(event ->
SpinChartsController spinCC = new SpinChartsController();
spinCC.closeProgram();
);
primaryStage.setHeight(800d);
primaryStage.setWidth(1000d);
primaryStage.setMinHeight(600d);
primaryStage.setMinWidth(800d);
primaryStage.setScene(scene);
primaryStage.setTitle("SpinCharts");
primaryStage.show();
public static void main(String[] args)
launch(args);
Please help me with that code I'm missing and be as specific as possible. Sorry if my post-editing is not too good, was doing my best, will improve in the future. Thanks.
java javafx
I am a beginner Java student who would like to call himself a developer one day. I've been studying stackoverflow for a while, found many solutions and useful informations. This is my first post so please don't be too harsh on me. I was trying to find solution to my problem by myself but failed.
I am trying to make my TableView cells with data react on MouseEvent leftclick (I want it to open different Image in Imageviewer below the table with data when I leftclick on the specific TableView cell).
This is for a Windows App.
My Main Controller:
package main;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class SpinChartsController implements Initializable
@FXML
MenuItem close;
@FXML
TableView<TableValues> tableView;
@FXML
TableColumn<TableValues, String> btn;
@FXML
TableColumn<TableValues, String> sBvsBtnLimp;
@FXML
TableColumn<TableValues, String> sBvsBtn;
@FXML
TableColumn<TableValues, String> sBvsBB;
@FXML
TableColumn<TableValues, String> bBvsBtn;
@FXML
TableColumn<TableValues, String> bBvsBtnLimp;
@FXML
TableColumn<TableValues, String> bBvs2pp;
@FXML
TableColumn<TableValues, String> bBvs2ppLimp;
@FXML
TableColumn<TableValues, String> bBvsSB;
@FXML
TableColumn<TableValues, String> bBvsSBLimp;
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
//ustawia kolumny w tabeli
btn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("Btn"));
sBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("sBvsBtnLimp"));
sBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBtn"));
sBvsBB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("SBvsBB"));
bBvsBtn.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtn"));
bBvsBtnLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsBtnLimp"));
bBvs2pp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2pp"));
bBvs2ppLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvs2ppLimp"));
bBvsSB.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSB"));
bBvsSBLimp.setCellValueFactory(new PropertyValueFactory<TableValues, String>("BBvsSBLimp"));
//dodanie danych do tabeli (dodawane wierszami)
tableView.setItems(getDataForTheTable());
//metoda dodajaca dane do tabeli wierszami
public ObservableList<TableValues> getDataForTheTable()
ObservableList<TableValues> rowsValues = FXCollections.observableArrayList();
rowsValues.add(new TableValues("", "", "vs AI", "", "vs AI", "",
"vs AI", "", "vs AI", ""));
rowsValues.add(new TableValues("25+", "", "", "", "", "",
"", "", "25+", "25+"));
rowsValues.add(new TableValues("20-25", "20+", "20+", "20+", "20+", "20+",
"20+", "20+", "20-25", "20-25"));
rowsValues.add(new TableValues("16-20", "16-20", "16-20", "16-20", "16-20", "16-20",
"16-20", "16-20", "16-20", "16-20"));
rowsValues.add(new TableValues("13-16", "13-16", "13-16", "13-16", "13-16", "13-16",
"13-16", "13-16", "13-16", "13-16"));
rowsValues.add(new TableValues("10-13", "10-13", "10-13", "10-13", "10-13", "10-13",
"10-13", "10-13", "10-13", "10-13"));
rowsValues.add(new TableValues("9", "8-10", "", "8-10", "8-10", "8-10",
"8-10", "8-10", "8-10", "8-10"));
rowsValues.add(new TableValues("8", "6-8", "", "6-8", "vs 3x 20-25", "",
"", "", "vs 2.5x-3x 20-25", "6-8"));
rowsValues.add(new TableValues("<8", "", "", "4-6", "", "",
"", "", "", "4-6"));
rowsValues.add(new TableValues("", "", "", "", "", "",
"", "", "", ""));
rowsValues.add(new TableValues("ODDS", "", "", "", "", "",
"", "", "", ""));
return rowsValues;
public void closeProgram()
Platform.exit();
System.exit(0);
My TableValues class:
package main;
import javafx.beans.property.SimpleStringProperty;
public class TableValues
//uzywam SimpleStringProperty do TableView bo ma listenery i moge potem z tym cos zrobic
private SimpleStringProperty Btn;
private SimpleStringProperty SBvsBtnLimp;
private SimpleStringProperty SBvsBtn;
private SimpleStringProperty SBvsBB;
private SimpleStringProperty BBvsBtn;
private SimpleStringProperty BBvsBtnLimp;
private SimpleStringProperty BBvs2pp;
private SimpleStringProperty BBvs2ppLimp;
private SimpleStringProperty BBvsSB;
private SimpleStringProperty BBvsSBLimp;
//taki konstruktor by bylo latwiej, beda podawane Stringi a on bedzie sobie sam zamienial
public TableValues(String btn, String SBvsBtnLimp, String SBvsBtn, String SBvsBB, String BBvsBtn,
String BBvsBtnLimp, String BBvs2pp, String BBvs2ppLimp, String BBvsSB, String BBvsSBLimp)
this.Btn = new SimpleStringProperty(btn);
this.SBvsBtnLimp = new SimpleStringProperty(SBvsBtnLimp);
this.SBvsBtn = new SimpleStringProperty(SBvsBtn);
this.SBvsBB = new SimpleStringProperty(SBvsBB);
this.BBvsBtn = new SimpleStringProperty(BBvsBtn);
this.BBvsBtnLimp = new SimpleStringProperty(BBvsBtnLimp);
this.BBvs2pp = new SimpleStringProperty(BBvs2pp);
this.BBvs2ppLimp = new SimpleStringProperty(BBvs2ppLimp);
this.BBvsSB = new SimpleStringProperty(BBvsSB);
this.BBvsSBLimp = new SimpleStringProperty(BBvsSBLimp);
public String getBtn()
return Btn.get();
public void setBtn(String btn)
this.Btn.set(btn);
public String getSBvsBtnLimp()
return SBvsBtnLimp.get();
public void setSBvsBtnLimp(String SBvsBTNLimp)
this.SBvsBtnLimp.set(SBvsBTNLimp);
public String getSBvsBtn()
return SBvsBtn.get();
public void setSBvsBtn(String SBvsBtn)
this.SBvsBtn.set(SBvsBtn);
public String getSBvsBB()
return SBvsBB.get();
public void setSBvsBB(String SBvsBB)
this.SBvsBB.set(SBvsBB);
public String getBBvsBtn()
return BBvsBtn.get();
public void setBBvsBtn(String BBvsBtn)
this.BBvsBtn.set(BBvsBtn);
public String getBBvsBtnLimp()
return BBvsBtnLimp.get();
public void setBBvsBtnLimp(String BBvsBtnLimp)
this.BBvsBtnLimp.set(BBvsBtnLimp);
public String getBBvs2pp()
return BBvs2pp.get();
public void setBBvs2pp(String BBvs2pp)
this.BBvs2pp.set(BBvs2pp);
public String getBBvs2ppLimp()
return BBvs2ppLimp.get();
public void setBBvs2ppLimp(String BBvs2ppLimp)
this.BBvs2ppLimp.set(BBvs2ppLimp);
public String getBBvsSB()
return BBvsSB.get();
public void setBBvsSB(String BBvsSB)
this.BBvsSB.set(BBvsSB);
public String getBBvsSBLimp()
return BBvsSBLimp.get();
public void setBBvsSBLimp(String BBvsSBLimp)
this.BBvsSBLimp.set(BBvsSBLimp);
My fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0"
prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="main.SpinChartsController">
<children>
<MenuBar StackPane.alignment="TOP_LEFT">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="close" mnemonicParsing="false" onAction="#closeProgram" text="Close"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About"/>
</items>
</Menu>
</menus>
</MenuBar>
<TableView fx:id="tableView" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="331.0" prefWidth="884.0"
StackPane.alignment="TOP_LEFT">
<columns>
<TableColumn fx:id="btn" prefWidth="67.99999463558197" sortable="false" text="BTN"/>
<TableColumn fx:id="sBvsBtnLimp" prefWidth="102.40003204345703" sortable="false" text="SB vs BTN Limp"/>
<TableColumn fx:id="sBvsBtn" prefWidth="76.00001525878906" sortable="false" text="SB vs BTN"/>
<TableColumn fx:id="sBvsBB" prefWidth="72.79998779296875" sortable="false" text="SB vs BB"/>
<TableColumn fx:id="bBvsBtn" prefWidth="84.0" sortable="false" text="BB vs BTN"/>
<TableColumn fx:id="bBvsBtnLimp" prefWidth="102.4000244140625" sortable="false" text="BB vs BTN Limp"/>
<TableColumn fx:id="bBvs2pp" prefWidth="84.80001831054688" sortable="false" text="BB vs 2pp"/>
<TableColumn fx:id="bBvs2ppLimp" prefWidth="101.5999755859375" sortable="false" text="BB vs 2pp Limp"/>
<TableColumn fx:id="bBvsSB" prefWidth="79.19989013671875" sortable="false" text="BB vs SB"/>
<TableColumn fx:id="bBvsSBLimp" prefWidth="108.800048828125" sortable="false" text="BB vs SB Limp"/>
</columns>
<StackPane.margin>
<Insets left="50.0" right="50.0" top="50.0"/>
</StackPane.margin>
</TableView>
</children>
</StackPane>
My Main class:
package main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SpinCharts extends Application
@Override
public void start(Stage primaryStage) throws Exception
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("fxmlfiles/spinCharts.fxml"));
StackPane stackPane = loader.load();
Scene scene = new Scene(stackPane);
primaryStage.getIcons().add(new Image("main/diamond.png"));
primaryStage.setOnCloseRequest(event ->
SpinChartsController spinCC = new SpinChartsController();
spinCC.closeProgram();
);
primaryStage.setHeight(800d);
primaryStage.setWidth(1000d);
primaryStage.setMinHeight(600d);
primaryStage.setMinWidth(800d);
primaryStage.setScene(scene);
primaryStage.setTitle("SpinCharts");
primaryStage.show();
public static void main(String[] args)
launch(args);
Please help me with that code I'm missing and be as specific as possible. Sorry if my post-editing is not too good, was doing my best, will improve in the future. Thanks.
java javafx
java javafx
asked Mar 27 at 14:52
wojciechwwojciechw
419 bronze badges
419 bronze badges
2
you need a custom TableCell implementation that registers the mouseHandler
– kleopatra
Mar 27 at 16:21
1
Ok, I will learn that. Thought I know that naming convention but will take a look at it again. Thank You for the feedback.
– wojciechw
Mar 27 at 18:52
add a comment |
2
you need a custom TableCell implementation that registers the mouseHandler
– kleopatra
Mar 27 at 16:21
1
Ok, I will learn that. Thought I know that naming convention but will take a look at it again. Thank You for the feedback.
– wojciechw
Mar 27 at 18:52
2
2
you need a custom TableCell implementation that registers the mouseHandler
– kleopatra
Mar 27 at 16:21
you need a custom TableCell implementation that registers the mouseHandler
– kleopatra
Mar 27 at 16:21
1
1
Ok, I will learn that. Thought I know that naming convention but will take a look at it again. Thank You for the feedback.
– wojciechw
Mar 27 at 18:52
Ok, I will learn that. Thought I know that naming convention but will take a look at it again. Thank You for the feedback.
– wojciechw
Mar 27 at 18:52
add a comment |
1 Answer
1
active
oldest
votes
You can set a cell factory and then set the mouse click listener to each cell:
column.setCellFactory(param -> new TableCell<TableValues, String>()
@Override
public void updateItem(String item, boolean empty)
super.updateItem(item, empty);
if (item == null
);
You have to set the cell factory to each column in your table, like you are already doing it with the PropertyValueFactory
. In that example code I also set the cursor to CLOSED_HAND
if the cell is clickable, but you don't have do do that.
It works. Thank You very much good Sir :) Now I need to code events with ImageViewer showing different images for different clicked cell.
– wojciechw
Mar 28 at 11:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380211%2fjavafx-how-to-set-a-mouseevent-leftclick-action-on-a-cell-with-data-in-tablevie%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can set a cell factory and then set the mouse click listener to each cell:
column.setCellFactory(param -> new TableCell<TableValues, String>()
@Override
public void updateItem(String item, boolean empty)
super.updateItem(item, empty);
if (item == null
);
You have to set the cell factory to each column in your table, like you are already doing it with the PropertyValueFactory
. In that example code I also set the cursor to CLOSED_HAND
if the cell is clickable, but you don't have do do that.
It works. Thank You very much good Sir :) Now I need to code events with ImageViewer showing different images for different clicked cell.
– wojciechw
Mar 28 at 11:23
add a comment |
You can set a cell factory and then set the mouse click listener to each cell:
column.setCellFactory(param -> new TableCell<TableValues, String>()
@Override
public void updateItem(String item, boolean empty)
super.updateItem(item, empty);
if (item == null
);
You have to set the cell factory to each column in your table, like you are already doing it with the PropertyValueFactory
. In that example code I also set the cursor to CLOSED_HAND
if the cell is clickable, but you don't have do do that.
It works. Thank You very much good Sir :) Now I need to code events with ImageViewer showing different images for different clicked cell.
– wojciechw
Mar 28 at 11:23
add a comment |
You can set a cell factory and then set the mouse click listener to each cell:
column.setCellFactory(param -> new TableCell<TableValues, String>()
@Override
public void updateItem(String item, boolean empty)
super.updateItem(item, empty);
if (item == null
);
You have to set the cell factory to each column in your table, like you are already doing it with the PropertyValueFactory
. In that example code I also set the cursor to CLOSED_HAND
if the cell is clickable, but you don't have do do that.
You can set a cell factory and then set the mouse click listener to each cell:
column.setCellFactory(param -> new TableCell<TableValues, String>()
@Override
public void updateItem(String item, boolean empty)
super.updateItem(item, empty);
if (item == null
);
You have to set the cell factory to each column in your table, like you are already doing it with the PropertyValueFactory
. In that example code I also set the cursor to CLOSED_HAND
if the cell is clickable, but you don't have do do that.
answered Mar 27 at 22:23
Samuel PhilippSamuel Philipp
7,7729 gold badges18 silver badges36 bronze badges
7,7729 gold badges18 silver badges36 bronze badges
It works. Thank You very much good Sir :) Now I need to code events with ImageViewer showing different images for different clicked cell.
– wojciechw
Mar 28 at 11:23
add a comment |
It works. Thank You very much good Sir :) Now I need to code events with ImageViewer showing different images for different clicked cell.
– wojciechw
Mar 28 at 11:23
It works. Thank You very much good Sir :) Now I need to code events with ImageViewer showing different images for different clicked cell.
– wojciechw
Mar 28 at 11:23
It works. Thank You very much good Sir :) Now I need to code events with ImageViewer showing different images for different clicked cell.
– wojciechw
Mar 28 at 11:23
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380211%2fjavafx-how-to-set-a-mouseevent-leftclick-action-on-a-cell-with-data-in-tablevie%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
you need a custom TableCell implementation that registers the mouseHandler
– kleopatra
Mar 27 at 16:21
1
Ok, I will learn that. Thought I know that naming convention but will take a look at it again. Thank You for the feedback.
– wojciechw
Mar 27 at 18:52