Results 1 to 17 of 17
Thread: Netbeans Jtable
- 11-05-2008, 01:18 PM #1
- 11-06-2008, 05:50 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Simply use getValueAt() method with the correct row/column index. It's return an Object, you have to cast into the correct type you want.
- 11-06-2008, 08:24 AM #3
- 11-06-2008, 08:27 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show your code here to see what you have done?Java Code:public void GetTableValues() { String str = (String) jTable1.getValueAt(1, 0); JOptionPane.showMessageDialog(null, str); }
- 11-06-2008, 08:45 AM #5
I still get an error."Illigal start of expression".In my code i want when i click the button,to get the values in the table and do some calculations on it.Can you figure out why the error msg is showing.Here is my code
/*public Object GetData(JTable xenon, int row_index, int col_index){
return xenon.getModel().getValueAt(row_index, col_index);
} */
- 11-06-2008, 08:48 AM #6
Sorry that was the wrong code.It should be like this:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
public void GetTableValues() {
String str = (String) Xenon.getValueAt(1, 0);
JOptionPane.showMessageDialog(null, str);
}
- 11-06-2008, 09:44 AM #7
Member
- Join Date
- Nov 2008
- Posts
- 10
- Rep Power
- 0
Hi Manfizy,
Try this:
Java Code:JOptionPane.showMessageDialog(null,jTable1.getValueAt(1,0).toString());
- 11-06-2008, 10:01 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 11-06-2008, 10:10 AM #9
- 11-06-2008, 10:22 AM #10
Thank you for your replies,am progressing.
Another question:
my table can only display fixed data.i want it to update and store data each time i run the program.how can i do that?
Thank you in advance
- 11-06-2008, 10:49 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In that case you have to use a data model.
- 11-06-2008, 10:56 AM #12
- 11-06-2008, 11:17 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show here what you have tried.
- 11-06-2008, 01:13 PM #14
Ok this is the code:
package MyXenonConc;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableModel;
public class XenonConcUI extends javax.swing.JFrame {
final String[] columnNames = {"Time(hh:mm)",
"Power Level(%)"};
final Object[][] data = {
{ new Float(5), new Integer(20)},
{ new Float(3), new Integer(23)},
{ new Float(2), new Integer(27)},
{new Float(20), new Integer(35)},
{new Float(10), new Integer(41)}
};
private boolean DEBUG = false;
private boolean ALLOW_COLUMN_SELECTION = true;
private boolean ALLOW_ROW_SELECTION = true;
/** Creates new form XenonConcUI */
public XenonConcUI() {
initComponents();
JTable Xenon = new JTable(new XenonConcUI());
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("No columns are selected.");
} else {
int selectedCol = lsm.getMinSelectionIndex();
System.out.println("Column " + selectedCol
+ " is now selected.");
}
}
This was just trial and error.Could you please show me how to go about it?
Thank you
- 11-12-2008, 09:22 AM #15
How can i diplay several values on the same pane?with the code show below i can only display the value of one cell
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
GetTableValues();
}
public void GetTableValues() {
String str = (String) Xenon.getValueAt(1, 0);
JOptionPane.showMessageDialog(null, str);
}
Thank you
- 11-12-2008, 03:52 PM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you want to deal with different cells, you need to change index values on getValueAt() method. It's designing is depends on your application. You should think about a way to get all values.
If you want to get all cell values, use a loop. May be two for loops, one for rows and the other columns.
- 11-13-2008, 09:15 AM #17
Similar Threads
-
Row Name In Jtable
By SANDY_INDIA in forum AWT / SwingReplies: 1Last Post: 08-16-2008, 12:23 AM -
Regarding JTable
By adeeb in forum AWT / SwingReplies: 12Last Post: 06-19-2008, 07:39 AM -
Regarding JTable
By adeeb in forum SWT / JFaceReplies: 0Last Post: 06-18-2008, 06:13 PM -
Jtable duplicates through Hashtable (JTable condition problem) my assignment plz help
By salmanpirzada1 in forum Advanced JavaReplies: 2Last Post: 05-15-2008, 10:15 AM -
How to add in a new row in Jtable?
By Ry4n in forum AWT / SwingReplies: 0Last Post: 01-18-2008, 12:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks