Get size of table by the value of 2 textFields

Hy!I want to make a table with number of rows and columns took from 2 texfields!I have 2 textFieldsfor row and column number and a Create button!I add 2 valkues for the textFields,for ex 6,7 and i push the create button and the table created has 6 rows and 7 columns!How can i do that?Any help?

Thanks

[314 byte] By [killer8685a] at [2007-11-27 11:41:03]
# 1

JTable jtb = new JTable(int numRows, int numColumns);

masijade.a at 2007-7-29 17:35:32 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks! I tried this one but it gives me a nullPointerException at : int row = Integer.parseInt(jTextfieldRow.getText()).

I don't know what to do to fix it!

killer8685a at 2007-7-29 17:35:32 > top of Java-index,Desktop,Core GUI APIs...
# 3

I made it this way!the int numRows = Integer.parseInt(jTextFieldRow.getText()).But when i run the applic it gaves me a nullPointerException!Any idea?

killer8685a at 2007-7-29 17:35:32 > top of Java-index,Desktop,Core GUI APIs...
# 4

Seeing the code for that may help.

masijade.a at 2007-7-29 17:35:32 > top of Java-index,Desktop,Core GUI APIs...
# 5

This is my code!I work with Eclipse!Here i have a Create button!I want the table to be created after i add the row and column numbers and push the button!But i dont know ho to do it.Please give me some indications!Thanks!

import javax.swing.JPanel;

import javax.swing.JLabel;

import java.awt.Rectangle;

import javax.swing.JTextField;

import javax.swing.JButton;

import javax.swing.JScrollPane;

import javax.swing.JTable;

public class Gamer extends JPanel {

private static final long serialVersionUID = 1L;

private JLabel jLabelRow = null;

private JTextField jTextFieldRow = null;

private JLabel jLabelColumn = null;

private JTextField jTextFieldColumn = null;

private JButton jButtonCreate = null;

private JScrollPane jScrollPane = null;

private JTable jTable = null;

int numberRows = Integer.parseInt(jTextFieldRow.getText());

int numerColumns = Integer.parseInt(jTextFieldColumn.getText());

/**

* This method initializes jTextFieldRow

*

* @return javax.swing.JTextField

*/

private JTextField getJTextFieldRow() {

if (jTextFieldRow == null) {

jTextFieldRow = new JTextField();

jTextFieldRow.setBounds(new Rectangle(105, 15, 76, 26));

}

return jTextFieldRow;

}

/**

* This method initializes jTextFieldColumn

*

* @return javax.swing.JTextField

*/

private JTextField getJTextFieldColumn() {

if (jTextFieldColumn == null) {

jTextFieldColumn = new JTextField();

jTextFieldColumn.setBounds(new Rectangle(320, 12, 76, 23));

}

return jTextFieldColumn;

}

/**

* This method initializes jButtonCreate

*

* @return javax.swing.JButton

*/

private JButton getJButtonCreate() {

if (jButtonCreate == null) {

jButtonCreate = new JButton();

jButtonCreate.setBounds(new Rectangle(436, 13, 108, 25));

jButtonCreate.setText("Create");

}

return jButtonCreate;

}

/**

* This method initializes jScrollPane

*

* @return javax.swing.JScrollPane

*/

private JScrollPane getJScrollPane() {

if (jScrollPane == null) {

jScrollPane = new JScrollPane();

jScrollPane.setBounds(new Rectangle(2, 61, 565, 403));

jScrollPane.setViewportView(getJTable());

}

return jScrollPane;

}

/**

* This method initializes jTable

*

* @return javax.swing.JTable

*/

private JTable getJTable() {

if (jTable == null) {

jTable = new JTable(numberRows,numerColumns);

}

return jTable;

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

}

/**

* This is the default constructor

*/

public Gamer() {

super();

initialize();

}

/**

* This method initializes this

*

* @return void

*/

private void initialize() {

jLabelColumn = new JLabel();

jLabelColumn.setBounds(new Rectangle(226, 14, 73, 23));

jLabelColumn.setText("Column Nr");

jLabelRow = new JLabel();

jLabelRow.setBounds(new Rectangle(14, 13, 70, 26));

jLabelRow.setText("Row Nr");

this.setSize(569, 464);

this.setLayout(null);

this.add(jLabelRow, null);

this.add(getJTextFieldRow(), null);

this.add(jLabelColumn, null);

this.add(getJTextFieldColumn(), null);

this.add(getJButtonCreate(), null);

this.add(getJScrollPane(), null);

}

} // @jve:decl-index=0:visual-constraint="10,10"

killer8685a at 2007-7-29 17:35:32 > top of Java-index,Desktop,Core GUI APIs...
# 6

Finally i made it!I used tableModel, and it worked!Thanks Masijade.

How can u help me how to put elements in the table?For example fill all the table cells with "1",even if a create a 4/4 table or a 10/10 table!

killer8685a at 2007-7-29 17:35:32 > top of Java-index,Desktop,Core GUI APIs...
# 7

> How can u help me how to put elements in the

> table?For example fill all the table cells with

> "1",even if a create a 4/4 table or a 10/10 table!

jtable.setValueAt("1", row, column);

or

jtable.getModel().setValueAt("1", row, column);

Yannix

Yannixa at 2007-7-29 17:35:32 > top of Java-index,Desktop,Core GUI APIs...