Re: Valid entry JTable
To: comp.lang.java.gui
RedGrittyBrick wrote:
Sriram wrote:
Hi
Is it possible to get valid entries say for example a list of valid
entries description in each cell of like the first two rows when the
user keeps adding rows and the mouse selection is on an empty cell
line after I click the Okaty button?
That is a very long and confusing sentence. I'd find it easier to
understand if you split it into several short sentences. Please also use
terms that others are more likely to understand. What is a "valid
entry"? Are you talking of the validation of the values in a field using
something like an InputVerifier? Or do you just want to print to stdout
the text values of some JTextFields? Or of some JTable cells?
Something like this -Valid entries
Cell value at rowno1,colno1 is ......
cell value at rowno1 colno2 is...
and so on....
Any references,sample code,links might help me
Did you just want to put some System.out.println statements in an
ActionListener associated with your "Okay" JButton?
I made you a code ... but I eated it.
Coff:
-------------------------------------8<---------------------------------
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
/**
* @author: RedGrittyBrick
*/
public class LOL implements ActionListener {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new LOL().createAndShowGUI();
}
});
}
static final String MOAR = "MOAR!", K = "KTHXBAI";
private int rows = 3, columns = 2;
JTextField[][] array = new JTextField[rows][columns];
private void createAndShowGUI() {
JPanel p = new JPanel(new GridLayout(rows+1, columns));
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
array[row][column] = new JTextField(10);
p.add(array[row][column]);
}
}
p.add(makeJButton(MOAR));
p.add(makeJButton(K));
JFrame f = new JFrame("LOL");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
private final JButton makeJButton(String label) {
JButton b = new JButton(label);
b.addActionListener(this);
return b;
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals(MOAR)) {
System.out.println("NOT WANT! (YET)");
} else if (command.equals(K)) {
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
System.out.println("Cell value at " + row
+ ", " + column
+ " is '" + array[row][column].getText()
+ "'.");
}
}
} else {
System.out.println("DOH!");
}
}
}
-------------------------------------8<---------------------------------
HTH (but somehow I doubt it)
--
RGB
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24