Results 1 to 3 of 3
  1. #1
    nor
    nor is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Thumbs down 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();
    }
    });
    }
    }

  2. #2
    hosscomp is offline Member
    Join Date
    Oct 2010
    Posts
    63
    Rep Power
    0

    Default

    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.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    Use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:
    CODE
    db

Similar Threads

  1. JButton help :)
    By yasmin k in forum AWT / Swing
    Replies: 7
    Last Post: 11-12-2009, 09:53 PM
  2. How to put a JButton in JTable thrid column?
    By prad3s4 in forum AWT / Swing
    Replies: 1
    Last Post: 11-02-2009, 04:54 AM
  3. Adding JButton to a JTable
    By ting.at.net@hotmail.com in forum AWT / Swing
    Replies: 6
    Last Post: 05-26-2009, 03:37 AM
  4. JButton to display JTable
    By Nemesis777 in forum New To Java
    Replies: 0
    Last Post: 12-08-2008, 12:16 PM
  5. Replies: 2
    Last Post: 05-15-2008, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •