Best way to create/save JTable

i want to know how to get data from table n save it in either text fil

Page 1 of 1

13 Replies - 20928 Views - Last Post: 16 August 2008 - 06:45 AM Rate Topic: -----

#1 deqa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-July 08

Best way to create/save JTable

Posted 28 July 2008 - 10:49 AM

hey all
i'm new to java world and i want to develop a game... its goes like this..
i'm goin to generate 5 random characters and display it in text field then i have a table that has 5 rows n four collumns, the user has to click in words that starts with each and every letter depending on categories i provide like names, animals, fruits and countries.....
for now i'm able to generate the random characters but i want to knw how to store the data, i'm nt sure if i should use text file or an array or linked list and yet i dont know how to implement them aswell.........coz i have to compare the entered data with data in text file i'm goin to provide....its all kind of blurry now....i need guidance..
for the record i'm using netbeans IDE...


plz some one help me and explain it to me.....
thnks in advance

Edited for a more meaninfull topic name

This post has been edited by pbl: 28 July 2008 - 06:40 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Best way to create/save JTable

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Best way to create/save JTable

Posted 28 July 2008 - 11:02 AM

Moved to the Java forum.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Best way to create/save JTable

Posted 28 July 2008 - 03:11 PM

The easiest way:

Just use a text file
Read it and populate your JTable with the elements read
May be the first digit in the text file might be the column number

0 Tulip
0 Rose
1 Canada
1 USA
2 Dog
2 Cat
3 Apple
3 Banana

The way I would do it

Write another application that populates the JTable (with titles and everything) by reading a text file or not
Save the JTable as an object into a file objectOutputStream.WriteObject(myTable);

import javax.swing.*;
import java.io.*;

public class CreateTable {

	static String[] header = {"Flowers", "Animals", "Fruits", "Country"};
	static String[][] elements = {
		{"Tulip",	"Dog",		"Apple",	"Canada"},
		{"Rose",	"Cat",		"Orange",	"USA"},
		{"Lys",		"Snake",	"Tobacco",	"Cuba"}
	};
		
	static public void main(String[] arg) {
		String filename = "table.file";
		JTable table = new JTable(elements, header);
		try {
			ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filename));
			oos.writeObject(table);
			oos.close();
		}
		catch(IOException e) {
			System.out.println("Problem creating table file: " + e);
			return;
		}
		System.out.println("JTable correctly saved to file " + filename);
	}
}



Then your original application can read back this JTable from the file and display it.

import javax.swing.*;
import java.io.*;

public class ReadTable extends JFrame{

	static String filename = "table.file";
	JTable table;
	
	ReadTable() {
		super("Test table");
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		try {
			ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename));
			table = (JTable) ois.readObject();
		}
		catch(Exception e) {
			System.out.println("Problem reading back table from file: " + filename);
			return;
		}
		add(new JScrollPane(table));
		setSize(400, 300);
	}
		
	static public void main(String[] arg) {
		ReadTable rt = new ReadTable();
		rt.setVisible(true);
	}
}



Edited because I had the time to write the code because (I guess we are in a perfect world without bug) nobody else is on the forum this evening

This post has been edited by pbl: 28 July 2008 - 04:30 PM

Was This Post Helpful? 1
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Best way to create/save JTable

Posted 28 July 2008 - 06:48 PM

That's not true...I'm on most of the time :). It's been a slow day on the Programming Help Forums...at least in VB, Java and VB.NET. :unsure:

Edit: Good call on the title moderation, "jtable in netbeans" was a little lacking. :D

This post has been edited by Locke37: 28 July 2008 - 06:49 PM

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Best way to create/save JTable

Posted 28 July 2008 - 07:12 PM

View PostLocke37, on 28 Jul, 2008 - 06:48 PM, said:

Good call on the title moderation, "jtable in netbeans" was a little lacking. :D

Thanks,

I am going in a crusade here
Newbies confused IDE and Java programming
I want to help them understand that these are 2 different issues
I learned Java the hard way... Notepad and a console window... I think it is the better way
That is why I have no problem (and I do it) spending time correcting code of people saying "does not compile"
takes me 5 seconds to cut & paste in my Eclipse IDE and write down the answer... this is my conception of "pedagogic approach". I might be wrong on that. So I will never suggest "use an IDE" but I will spend hours here correcting basic syntax errors.
Was This Post Helpful? 0
  • +
  • -

#6 deqa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-July 08

Re: Best way to create/save JTable

Posted 31 July 2008 - 10:49 AM

hey thanks alot for the help man.....but the problem is, you specified the entry data already and mine the user has to put in the data...the table header i already have, i mean designed in netbeans and thats the problem...its all made easy i get to drag n drop but i cant see how the table is trying to manage my data cause in my source code i have only the table not the row by collumn thing, i mean the cells so i cant possibly access it.....i read java swing book and its explaining to me like you did, the one you created the array for the entry....if your familiar with netbeans ... or even without netbeans jst like yours, can you NOT specify the entry data and prompt for the user to input ...
[/quote]
static String[] header = {"Flowers", "Animals", "Fruits", "Country"};
static String[][] elements = {
{"Tulip", "Dog", "Apple", "Canada"},
{"Rose", "Cat", "Orange", "USA"},
{"Lys", "Snake", "Tobacco", "Cuba"}
};

your code is like this but mine xcept the header i want the enter the data and i should read in wat eva they click in to compare with the one i'll be storing in text file .....
can u explain a little more plz...

thnks in advance

sry if my english is not so good n i have repetition of words...i hop u get wat i'm tryin to say
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Best way to create/save JTable

Posted 31 July 2008 - 04:56 PM

View Postdeqa, on 28 Jul, 2008 - 10:49 AM, said:

i'm goin to generate 5 random characters and display it in text field then i have a table that has 5 rows n four collumns, the user has to click in words that starts with each and every letter depending on categories i provide like names, animals, fruits and countries.....

If the user has to "click in words that starts with each and every letter" I assumed that the Jtable was populated....
Was This Post Helpful? 0
  • +
  • -

#8 deqa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-July 08

Re: Best way to create/save JTable

Posted 01 August 2008 - 03:04 AM

" I assumed that the Jtable was populated".... i dont suppose i know wat u mean abt populated can plz tell me wat that is...
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Best way to create/save JTable

Posted 01 August 2008 - 04:54 AM

View Postdeqa, on 1 Aug, 2008 - 03:04 AM, said:

" I assumed that the Jtable was populated".... i dont suppose i know wat u mean abt populated can plz tell me wat that is...


You said "i have a table that has 5 rows n four collumns, the user has to click in words that starts with each and every letter"
That means that there is already text in your table

If I look at your initial post " i want to knw how to store the data, i'm nt sure if i should use text file "

So what do you want to save ?
Was This Post Helpful? 0
  • +
  • -

#10 deqa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-July 08

Re: Best way to create/save JTable

Posted 01 August 2008 - 05:21 AM

/*
* WordPower.java
*
* Created on July 26, 2008, 4:18 PM
*/

package project;

/**
*
* @author DEQA OSMAN
*/
public class WordPower extends javax.swing.JFrame {

/** Creates new form WordPower */
public WordPower() {
initComponents();
}




public void doRandomCharacter(){
double randomNumber;
double randomNumberSetup;
char randomCharacter;
for (int i = 0; i < 5; i++) {
randomNumber = Math.random();
randomNumberSetup = (randomNumber * 26 + 'A');
randomCharacter = (char) randomNumberSetup;
System.out.print(randomCharacter + " ");
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/

// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 204, 255));

jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"ALPHABETS", "NAMES", "PLACES", "ANIMALS", "THINGS"
}
) {
boolean[] canEdit = new boolean [] {
false, true, true, true, true
};

public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jTable1.setColumnSelectionAllowed(true);
jTable1.setRowHeight(27);
jTable1.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jTable1.getColumnModel().getColumn(1).setResizable(false);
jTable1.getColumnModel().getColumn(2).setResizable(false);
jTable1.getColumnModel().getColumn(3).setResizable(false);
jTable1.getColumnModel().getColumn(4).setResizable(false);

jButton2.setBackground(new java.awt.Color(0, 153, 153));
jButton2.setText("OK");

jButton1.setText("ALPHABETS");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jTextField1.setEditable(false);

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(112, 112, 112)
.add(jButton1)
.add(46, 46, 46)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(250, Short.MAX_VALUE))
.add(jPanel1Layout.createSequentialGroup()
.add(228, 228, 228)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(278, Short.MAX_VALUE))
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
.add(19, 19, 19))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.add(18, 18, 18)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(jButton2)
.addContainerGap(45, Short.MAX_VALUE))
);

jMenuBar1.setBackground(new java.awt.Color(0, 153, 153));

jMenu1.setText("NEW GAME");
jMenuBar1.add(jMenu1);

jMenu2.setText("INSTRUCTIONS");
jMenuBar1.add(jMenu2);

jMenu3.setText("HIGH SCORES");
jMenuBar1.add(jMenu3);

jMenu4.setText("HELP");
jMenuBar1.add(jMenu4);

setJMenuBar(jMenuBar1);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
doRandomCharacter();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WordPower().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

}

this is my source code and i can run this program now but it doesnt do anything meaning all the action listeners are not performing anythin except the random characters....the user can still click in some words in the table but i'm afraid nothin else is happening so wat i wanted to do was store wat the user enters in a txt file and then compare with another one..... the thing is.. when i asked few ppl i thought dey could help all they said was use vector or linked ist or an array to store the table contents then compare with the txt file contents and i thought i could use txt file to store the data straight frm d table... is it possible ....coz this code is developed in netbeans as u cn see n i didnt do all that coding its jst drag n drop i did..except the method for random characters..
wat do u think i could do now...
thnx alot
Was This Post Helpful? 0
  • +
  • -

#11 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Best way to create/save JTable

Posted 01 August 2008 - 08:35 AM

One quick thing...:code:
Was This Post Helpful? 0
  • +
  • -

#12 deqa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-July 08

Re: Best way to create/save JTable

Posted 02 August 2008 - 03:22 AM

*
* WordPower.java
*
* Created on July 26, 2008, 4:18 PM
*/

package project;

/**
*
* @author DEQA OSMAN 
*/
public class WordPower extends javax.swing.JFrame {

/** Creates new form WordPower */
public WordPower() {
initComponents();
}




public void doRandomCharacter(){
double randomNumber;
double randomNumberSetup;
char randomCharacter;
for (int i = 0; i < 5; i++) {
randomNumber = Math.random();
randomNumberSetup = (randomNumber * 26 + 'A');
randomCharacter = (char) randomNumberSetup; 
System.out.print(randomCharacter + " ");
}
} 
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/

// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 204, 255));

jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"ALPHABETS", "NAMES", "PLACES", "ANIMALS", "THINGS"
}
) {
boolean[] canEdit = new boolean [] {
false, true, true, true, true
};

public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jTable1.setColumnSelectionAllowed(true);
jTable1.setRowHeight(27);
jTable1.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jTable1.getColumnModel().getColumn(1).setResizable(false);
jTable1.getColumnModel().getColumn(2).setResizable(false);
jTable1.getColumnModel().getColumn(3).setResizable(false);
jTable1.getColumnModel().getColumn(4).setResizable(false);

jButton2.setBackground(new java.awt.Color(0, 153, 153));
jButton2.setText("OK");

jButton1.setText("ALPHABETS");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jTextField1.setEditable(false);

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(112, 112, 112)
.add(jButton1)
.add(46, 46, 46)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(250, Short.MAX_VALUE))
.add(jPanel1Layout.createSequentialGroup()
.add(228, 228, 228)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(278, Short.MAX_VALUE))
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
.add(19, 19, 19))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton1))
.add(18, 18, 18)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(jButton2)
.addContainerGap(45, Short.MAX_VALUE))
);

jMenuBar1.setBackground(new java.awt.Color(0, 153, 153));

jMenu1.setText("NEW GAME");
jMenuBar1.add(jMenu1);

jMenu2.setText("INSTRUCTIONS");
jMenuBar1.add(jMenu2);

jMenu3.setText("HIGH SCORES");
jMenuBar1.add(jMenu3);

jMenu4.setText("HELP");
jMenuBar1.add(jMenu4);

setJMenuBar(jMenuBar1);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
doRandomCharacter();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WordPower().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

}


Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Best way to create/save JTable

Posted 02 August 2008 - 10:12 AM

View Postdeqa, on 1 Aug, 2008 - 05:21 AM, said:

this is my source code and i can run this program now but it doesnt do anything meaning all the action listeners are not performing anythin except the random characters....


In all your code there is only one listener for jButton1
So when you say "all the action listeners are not performing"... yes the only one you have performs

Quote

the user can still click in some words in the table but i'm afraid nothin else is happening

Yes, there are no listener on the JTable

Quote

so wat i wanted to do was store wat the user enters in a txt file and then compare with another one.....


Sorry still don't undertsand your problem or what you want to do.
We have a serious communication problem here.
Have a friend who can translate your problem in English (or even in French) to help you post your problem here

As I don't have access to org.jdesktop I cannot test your code
Was This Post Helpful? 0
  • +
  • -

#14 deqa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-July 08

Re: Best way to create/save JTable

Posted 16 August 2008 - 06:45 AM

hey again
i read alot of stuff and basically i didnt know that much about jTable but now i am a bit familiar with it.

First, i thought my problem can be solved with one click at some icon in netbeans but as i was reading about the table i figured out its a bit more complicated than that.

I read this some where "The Netbeans table editor can only populate a table with constant data.
To use variable data you need to add code. You create your own DefaultTableModel, probably in the constructor of whatever form you are creating. You link it to the JTable in Netbeans by setting the model property
to Form Connection/User Code and enter the model variable name.


I understand jTable in netbeans provides a default table model and it works with constant data and my aim is to work with data that changes at runtime, so i understand i need to specify my table model probably use Abstract table model and link it to the netbeans.

I also read that table data comes from database usually but i'm trying to generate data at runtime and capture that data in an array of strings first, then compare it with values i store in text file...the last task is left for later but now plz i want you to help me understand how do i extend that AbstractTableModel class.

thnx in advance
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1