How to display matrix in JavaFX












-1















I have two text fields and button. First one will have number of rows, second one will have number of columns. Button should create table with that numbers, then do some stuff with the elements of this table. Is there any analogue of GridView from C# for that? Because as I see I can't change number of rows in TableView and I think this will cause problem in future calculations. There is example from c#:



n = Int32.Parse(numericUpDown1.Text);
m = Int32.Parse(numericUpDown2.Text);
dataGridView1.RowCount = n;
dataGridView1.ColumnCount = m;


enter image description here



What can I use to do the same in Java?










share|improve this question




















  • 1





    Have you considered using a GridPane?

    – fabian
    Nov 13 '18 at 16:51











  • You could try ContolsFX GridView. stackoverflow.com/questions/52968067/…

    – Sedrick
    Nov 13 '18 at 21:47
















-1















I have two text fields and button. First one will have number of rows, second one will have number of columns. Button should create table with that numbers, then do some stuff with the elements of this table. Is there any analogue of GridView from C# for that? Because as I see I can't change number of rows in TableView and I think this will cause problem in future calculations. There is example from c#:



n = Int32.Parse(numericUpDown1.Text);
m = Int32.Parse(numericUpDown2.Text);
dataGridView1.RowCount = n;
dataGridView1.ColumnCount = m;


enter image description here



What can I use to do the same in Java?










share|improve this question




















  • 1





    Have you considered using a GridPane?

    – fabian
    Nov 13 '18 at 16:51











  • You could try ContolsFX GridView. stackoverflow.com/questions/52968067/…

    – Sedrick
    Nov 13 '18 at 21:47














-1












-1








-1








I have two text fields and button. First one will have number of rows, second one will have number of columns. Button should create table with that numbers, then do some stuff with the elements of this table. Is there any analogue of GridView from C# for that? Because as I see I can't change number of rows in TableView and I think this will cause problem in future calculations. There is example from c#:



n = Int32.Parse(numericUpDown1.Text);
m = Int32.Parse(numericUpDown2.Text);
dataGridView1.RowCount = n;
dataGridView1.ColumnCount = m;


enter image description here



What can I use to do the same in Java?










share|improve this question
















I have two text fields and button. First one will have number of rows, second one will have number of columns. Button should create table with that numbers, then do some stuff with the elements of this table. Is there any analogue of GridView from C# for that? Because as I see I can't change number of rows in TableView and I think this will cause problem in future calculations. There is example from c#:



n = Int32.Parse(numericUpDown1.Text);
m = Int32.Parse(numericUpDown2.Text);
dataGridView1.RowCount = n;
dataGridView1.ColumnCount = m;


enter image description here



What can I use to do the same in Java?







java javafx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 6:47







LokiTheCreator

















asked Nov 13 '18 at 16:34









LokiTheCreatorLokiTheCreator

667




667








  • 1





    Have you considered using a GridPane?

    – fabian
    Nov 13 '18 at 16:51











  • You could try ContolsFX GridView. stackoverflow.com/questions/52968067/…

    – Sedrick
    Nov 13 '18 at 21:47














  • 1





    Have you considered using a GridPane?

    – fabian
    Nov 13 '18 at 16:51











  • You could try ContolsFX GridView. stackoverflow.com/questions/52968067/…

    – Sedrick
    Nov 13 '18 at 21:47








1




1





Have you considered using a GridPane?

– fabian
Nov 13 '18 at 16:51





Have you considered using a GridPane?

– fabian
Nov 13 '18 at 16:51













You could try ContolsFX GridView. stackoverflow.com/questions/52968067/…

– Sedrick
Nov 13 '18 at 21:47





You could try ContolsFX GridView. stackoverflow.com/questions/52968067/…

– Sedrick
Nov 13 '18 at 21:47












1 Answer
1






active

oldest

votes


















0














Java Swing had a JTable. In Java FX that control is called TableView.
https://docs.oracle.com/javafx/2/ui_controls/table-view.htm



It's a pretty complicated control. You have to create a Table and then add 'column' objects to the table object like below:



DefaultTableModel tableModel = new DefaultTableModel();



    javax.swing.JComboBox<Integer> jComboBoxRows = new javax.swing.JComboBox<>();
javax.swing.JComboBox<Integer> jComboBoxColumns = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Simple JTable Example");

jComboBoxRows.setModel(new javax.swing.DefaultComboBoxModel<>(new Integer{1, 2, 3, 4}));

jTable1.setModel(tableModel);

jComboBoxRows.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableRowValue = (Integer) jComboBoxRows.getSelectedItem();
tableModel.setNumRows(tableRowValue.intValue());
tableModel.fireTableDataChanged();
}
});

jComboBoxColumns.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableColumnValue = (Integer) jComboBoxColumns.getSelectedItem();
tableModel.setColumnCount(tableColumnValue.intValue());
tableModel.fireTableDataChanged();
}
});


This is VERY generic. Basically you use a 'DefaultTableModel' and change the model using a 'set' or 'add' or 'remove' for columns and rows. Then you MUST FIRE an event so the UI will refresh based on model changes. The two listeners are naive but it puts you on the correct path. Sorry I couldn't give a better example. Running out of time... :-)



Good luck!






share|improve this answer


























  • I added screenshot of Windows Forms example. User enters some numbers in the cells, then programm do some stuff with that. TableView confuses me because I can't control number of visible rows, so the only way I see to show user where he should print numbers is to set Promt text "enter numbers here" and make other rows uneditable. That will look pretty goofy for me, am I missing something that can make it look prerry?

    – LokiTheCreator
    Nov 13 '18 at 17:23













  • If you just want to do it in 'Java' tables in JavaSwing are MUCH easier.

    – Waxhaw
    Nov 13 '18 at 17:37











  • I'll edit my answer to use Java Swing. ;-)

    – Waxhaw
    Nov 13 '18 at 18:39











  • ehh .. the question (unclear as it is ;) doesn't seem to be about Swing. @LokiTheCreator I think you should read some basic tutorial on whatever framework you want to use, for fx there are some references on the info tab of the javafx tag

    – kleopatra
    Nov 14 '18 at 9:03











  • even if Swing would be the theme - your answer is plain wrong: you never-ever need to call any of the tableModel.fireXX methods in application code if everything is wired correctly ...

    – kleopatra
    Nov 14 '18 at 9:06













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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285544%2fhow-to-display-matrix-in-javafx%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









0














Java Swing had a JTable. In Java FX that control is called TableView.
https://docs.oracle.com/javafx/2/ui_controls/table-view.htm



It's a pretty complicated control. You have to create a Table and then add 'column' objects to the table object like below:



DefaultTableModel tableModel = new DefaultTableModel();



    javax.swing.JComboBox<Integer> jComboBoxRows = new javax.swing.JComboBox<>();
javax.swing.JComboBox<Integer> jComboBoxColumns = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Simple JTable Example");

jComboBoxRows.setModel(new javax.swing.DefaultComboBoxModel<>(new Integer{1, 2, 3, 4}));

jTable1.setModel(tableModel);

jComboBoxRows.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableRowValue = (Integer) jComboBoxRows.getSelectedItem();
tableModel.setNumRows(tableRowValue.intValue());
tableModel.fireTableDataChanged();
}
});

jComboBoxColumns.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableColumnValue = (Integer) jComboBoxColumns.getSelectedItem();
tableModel.setColumnCount(tableColumnValue.intValue());
tableModel.fireTableDataChanged();
}
});


This is VERY generic. Basically you use a 'DefaultTableModel' and change the model using a 'set' or 'add' or 'remove' for columns and rows. Then you MUST FIRE an event so the UI will refresh based on model changes. The two listeners are naive but it puts you on the correct path. Sorry I couldn't give a better example. Running out of time... :-)



Good luck!






share|improve this answer


























  • I added screenshot of Windows Forms example. User enters some numbers in the cells, then programm do some stuff with that. TableView confuses me because I can't control number of visible rows, so the only way I see to show user where he should print numbers is to set Promt text "enter numbers here" and make other rows uneditable. That will look pretty goofy for me, am I missing something that can make it look prerry?

    – LokiTheCreator
    Nov 13 '18 at 17:23













  • If you just want to do it in 'Java' tables in JavaSwing are MUCH easier.

    – Waxhaw
    Nov 13 '18 at 17:37











  • I'll edit my answer to use Java Swing. ;-)

    – Waxhaw
    Nov 13 '18 at 18:39











  • ehh .. the question (unclear as it is ;) doesn't seem to be about Swing. @LokiTheCreator I think you should read some basic tutorial on whatever framework you want to use, for fx there are some references on the info tab of the javafx tag

    – kleopatra
    Nov 14 '18 at 9:03











  • even if Swing would be the theme - your answer is plain wrong: you never-ever need to call any of the tableModel.fireXX methods in application code if everything is wired correctly ...

    – kleopatra
    Nov 14 '18 at 9:06


















0














Java Swing had a JTable. In Java FX that control is called TableView.
https://docs.oracle.com/javafx/2/ui_controls/table-view.htm



It's a pretty complicated control. You have to create a Table and then add 'column' objects to the table object like below:



DefaultTableModel tableModel = new DefaultTableModel();



    javax.swing.JComboBox<Integer> jComboBoxRows = new javax.swing.JComboBox<>();
javax.swing.JComboBox<Integer> jComboBoxColumns = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Simple JTable Example");

jComboBoxRows.setModel(new javax.swing.DefaultComboBoxModel<>(new Integer{1, 2, 3, 4}));

jTable1.setModel(tableModel);

jComboBoxRows.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableRowValue = (Integer) jComboBoxRows.getSelectedItem();
tableModel.setNumRows(tableRowValue.intValue());
tableModel.fireTableDataChanged();
}
});

jComboBoxColumns.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableColumnValue = (Integer) jComboBoxColumns.getSelectedItem();
tableModel.setColumnCount(tableColumnValue.intValue());
tableModel.fireTableDataChanged();
}
});


This is VERY generic. Basically you use a 'DefaultTableModel' and change the model using a 'set' or 'add' or 'remove' for columns and rows. Then you MUST FIRE an event so the UI will refresh based on model changes. The two listeners are naive but it puts you on the correct path. Sorry I couldn't give a better example. Running out of time... :-)



Good luck!






share|improve this answer


























  • I added screenshot of Windows Forms example. User enters some numbers in the cells, then programm do some stuff with that. TableView confuses me because I can't control number of visible rows, so the only way I see to show user where he should print numbers is to set Promt text "enter numbers here" and make other rows uneditable. That will look pretty goofy for me, am I missing something that can make it look prerry?

    – LokiTheCreator
    Nov 13 '18 at 17:23













  • If you just want to do it in 'Java' tables in JavaSwing are MUCH easier.

    – Waxhaw
    Nov 13 '18 at 17:37











  • I'll edit my answer to use Java Swing. ;-)

    – Waxhaw
    Nov 13 '18 at 18:39











  • ehh .. the question (unclear as it is ;) doesn't seem to be about Swing. @LokiTheCreator I think you should read some basic tutorial on whatever framework you want to use, for fx there are some references on the info tab of the javafx tag

    – kleopatra
    Nov 14 '18 at 9:03











  • even if Swing would be the theme - your answer is plain wrong: you never-ever need to call any of the tableModel.fireXX methods in application code if everything is wired correctly ...

    – kleopatra
    Nov 14 '18 at 9:06
















0












0








0







Java Swing had a JTable. In Java FX that control is called TableView.
https://docs.oracle.com/javafx/2/ui_controls/table-view.htm



It's a pretty complicated control. You have to create a Table and then add 'column' objects to the table object like below:



DefaultTableModel tableModel = new DefaultTableModel();



    javax.swing.JComboBox<Integer> jComboBoxRows = new javax.swing.JComboBox<>();
javax.swing.JComboBox<Integer> jComboBoxColumns = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Simple JTable Example");

jComboBoxRows.setModel(new javax.swing.DefaultComboBoxModel<>(new Integer{1, 2, 3, 4}));

jTable1.setModel(tableModel);

jComboBoxRows.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableRowValue = (Integer) jComboBoxRows.getSelectedItem();
tableModel.setNumRows(tableRowValue.intValue());
tableModel.fireTableDataChanged();
}
});

jComboBoxColumns.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableColumnValue = (Integer) jComboBoxColumns.getSelectedItem();
tableModel.setColumnCount(tableColumnValue.intValue());
tableModel.fireTableDataChanged();
}
});


This is VERY generic. Basically you use a 'DefaultTableModel' and change the model using a 'set' or 'add' or 'remove' for columns and rows. Then you MUST FIRE an event so the UI will refresh based on model changes. The two listeners are naive but it puts you on the correct path. Sorry I couldn't give a better example. Running out of time... :-)



Good luck!






share|improve this answer















Java Swing had a JTable. In Java FX that control is called TableView.
https://docs.oracle.com/javafx/2/ui_controls/table-view.htm



It's a pretty complicated control. You have to create a Table and then add 'column' objects to the table object like below:



DefaultTableModel tableModel = new DefaultTableModel();



    javax.swing.JComboBox<Integer> jComboBoxRows = new javax.swing.JComboBox<>();
javax.swing.JComboBox<Integer> jComboBoxColumns = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Simple JTable Example");

jComboBoxRows.setModel(new javax.swing.DefaultComboBoxModel<>(new Integer{1, 2, 3, 4}));

jTable1.setModel(tableModel);

jComboBoxRows.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableRowValue = (Integer) jComboBoxRows.getSelectedItem();
tableModel.setNumRows(tableRowValue.intValue());
tableModel.fireTableDataChanged();
}
});

jComboBoxColumns.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Integer tableColumnValue = (Integer) jComboBoxColumns.getSelectedItem();
tableModel.setColumnCount(tableColumnValue.intValue());
tableModel.fireTableDataChanged();
}
});


This is VERY generic. Basically you use a 'DefaultTableModel' and change the model using a 'set' or 'add' or 'remove' for columns and rows. Then you MUST FIRE an event so the UI will refresh based on model changes. The two listeners are naive but it puts you on the correct path. Sorry I couldn't give a better example. Running out of time... :-)



Good luck!







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 18:42

























answered Nov 13 '18 at 17:05









WaxhawWaxhaw

274




274













  • I added screenshot of Windows Forms example. User enters some numbers in the cells, then programm do some stuff with that. TableView confuses me because I can't control number of visible rows, so the only way I see to show user where he should print numbers is to set Promt text "enter numbers here" and make other rows uneditable. That will look pretty goofy for me, am I missing something that can make it look prerry?

    – LokiTheCreator
    Nov 13 '18 at 17:23













  • If you just want to do it in 'Java' tables in JavaSwing are MUCH easier.

    – Waxhaw
    Nov 13 '18 at 17:37











  • I'll edit my answer to use Java Swing. ;-)

    – Waxhaw
    Nov 13 '18 at 18:39











  • ehh .. the question (unclear as it is ;) doesn't seem to be about Swing. @LokiTheCreator I think you should read some basic tutorial on whatever framework you want to use, for fx there are some references on the info tab of the javafx tag

    – kleopatra
    Nov 14 '18 at 9:03











  • even if Swing would be the theme - your answer is plain wrong: you never-ever need to call any of the tableModel.fireXX methods in application code if everything is wired correctly ...

    – kleopatra
    Nov 14 '18 at 9:06





















  • I added screenshot of Windows Forms example. User enters some numbers in the cells, then programm do some stuff with that. TableView confuses me because I can't control number of visible rows, so the only way I see to show user where he should print numbers is to set Promt text "enter numbers here" and make other rows uneditable. That will look pretty goofy for me, am I missing something that can make it look prerry?

    – LokiTheCreator
    Nov 13 '18 at 17:23













  • If you just want to do it in 'Java' tables in JavaSwing are MUCH easier.

    – Waxhaw
    Nov 13 '18 at 17:37











  • I'll edit my answer to use Java Swing. ;-)

    – Waxhaw
    Nov 13 '18 at 18:39











  • ehh .. the question (unclear as it is ;) doesn't seem to be about Swing. @LokiTheCreator I think you should read some basic tutorial on whatever framework you want to use, for fx there are some references on the info tab of the javafx tag

    – kleopatra
    Nov 14 '18 at 9:03











  • even if Swing would be the theme - your answer is plain wrong: you never-ever need to call any of the tableModel.fireXX methods in application code if everything is wired correctly ...

    – kleopatra
    Nov 14 '18 at 9:06



















I added screenshot of Windows Forms example. User enters some numbers in the cells, then programm do some stuff with that. TableView confuses me because I can't control number of visible rows, so the only way I see to show user where he should print numbers is to set Promt text "enter numbers here" and make other rows uneditable. That will look pretty goofy for me, am I missing something that can make it look prerry?

– LokiTheCreator
Nov 13 '18 at 17:23







I added screenshot of Windows Forms example. User enters some numbers in the cells, then programm do some stuff with that. TableView confuses me because I can't control number of visible rows, so the only way I see to show user where he should print numbers is to set Promt text "enter numbers here" and make other rows uneditable. That will look pretty goofy for me, am I missing something that can make it look prerry?

– LokiTheCreator
Nov 13 '18 at 17:23















If you just want to do it in 'Java' tables in JavaSwing are MUCH easier.

– Waxhaw
Nov 13 '18 at 17:37





If you just want to do it in 'Java' tables in JavaSwing are MUCH easier.

– Waxhaw
Nov 13 '18 at 17:37













I'll edit my answer to use Java Swing. ;-)

– Waxhaw
Nov 13 '18 at 18:39





I'll edit my answer to use Java Swing. ;-)

– Waxhaw
Nov 13 '18 at 18:39













ehh .. the question (unclear as it is ;) doesn't seem to be about Swing. @LokiTheCreator I think you should read some basic tutorial on whatever framework you want to use, for fx there are some references on the info tab of the javafx tag

– kleopatra
Nov 14 '18 at 9:03





ehh .. the question (unclear as it is ;) doesn't seem to be about Swing. @LokiTheCreator I think you should read some basic tutorial on whatever framework you want to use, for fx there are some references on the info tab of the javafx tag

– kleopatra
Nov 14 '18 at 9:03













even if Swing would be the theme - your answer is plain wrong: you never-ever need to call any of the tableModel.fireXX methods in application code if everything is wired correctly ...

– kleopatra
Nov 14 '18 at 9:06







even if Swing would be the theme - your answer is plain wrong: you never-ever need to call any of the tableModel.fireXX methods in application code if everything is wired correctly ...

– kleopatra
Nov 14 '18 at 9:06




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285544%2fhow-to-display-matrix-in-javafx%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

The Sandy Post