Results 1 to 3 of 3
Thread: sos help in jbutton -jtable
- 01-02-2011, 07:37 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
sos help in jbutton -jtable
hello ,
i am new in java and i have a project on creating a 6button menu in a gui application by using netbeans.
I created the menu using jframe and then i started designing the code for the first button-option.
The first option is that if selected by user a jtable must appear with 12 details for 7 employees which details are given in a txt file.
These details are given in this order:
code,name,surname,address,city,postCode,phone,emai l,department(int),typeOfEmployee,wage,typeOfEmploy ee
I also created the code for reading the txt file and create the jtable
The problems:
1) when running the jtable opens automatically together with the menu pannel
2) it appears to be empty
the code for creating the jtable is :
package paradoteo3o;
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
/**
*
* @author nora
*/
@SuppressWarnings ("serial")
public class menu extends JPanel{
public static final String file_name = "Employees.txt";
public static final String[] columns = {"Κωδικός Εργαζομένου", "Όνομα", "Επίθετο", "Διεύθυνση","Πόλη","Τ.Κ","Τηλέφωνο","Email","Τμήμα ","Τύπος Εργαζομένου","Μισθός","Κωδικός Κάρτας"};
private JTable table=new JTable();
private DefaultTableModel model;
public menu(){
setLayout(new BorderLayout());
add(new JScrollPane(table),BorderLayout.CENTER);
Vector <String> columnNames=new Vector <String>(Arrays.asList(columns));
try {
Scanner scanner=new Scanner(new File(file_name));
int count=0;
Vector<Vector<String>> dataVector=new Vector<Vector<String>>();
Vector<String> rowVector=new Vector<String>();
while (scanner.hasNextLine()){
String line=scanner.nextLine();
rowVector.add(line);
count++;
count %=columns.length;
if (count==0){
dataVector.add(rowVector);
rowVector=new Vector<String>();
}
}
model=new DefaultTableModel(dataVector,columnNames);
table.setModel(model);
}
catch (FileNotFoundException e){
e.printStackTrace();
}
}
static void createAndShowGui(){
JFrame frame=new JFrame("ΠΡΟΒΟΛΗ ΣΤΟΙΧΕΙΩΝ ΕΡΓΑΖΟΜΕΝΩΝ");
frame.getContentPane().add(new menu());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}
- 01-03-2011, 09:07 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 63
- Rep Power
- 0
Is the data in your Employees.txt file comma separated, one line per employee?
If so, you need to split the line and add each field to the rowVector.
- 01-09-2011, 04:30 AM #3
Similar Threads
-
JButton help :)
By yasmin k in forum AWT / SwingReplies: 7Last Post: 11-12-2009, 09:53 PM -
How to put a JButton in JTable thrid column?
By prad3s4 in forum AWT / SwingReplies: 1Last Post: 11-02-2009, 04:54 AM -
Adding JButton to a JTable
By ting.at.net@hotmail.com in forum AWT / SwingReplies: 6Last Post: 05-26-2009, 03:37 AM -
JButton to display JTable
By Nemesis777 in forum New To JavaReplies: 0Last Post: 12-08-2008, 12:16 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


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks