How i use jtable

hi master
sir how i use jtable
please send me any detail sample with swing interfas and code
thank's
aamir

Did you read the JTable API???
You will find a link titled "How to Use Tables" that takes you to the Swing tutorial.

Similar Messages

  • How to use Jtable cell Editor

    HI,
    Here trying to populate the ImageIcon using JLabel in Jtable cell. For that I used DefaultCellRenderer. For implement the mouseListener to label I used the DefaultCellEditor. I am facing one problem here. After editing the label I selected the second row of the table, the first row image is not displaying. Can any one help on this issue?
    public class LabelCellEditor extends DefaultCellEditor {
    public LabelCellEditor(final JCheckBox checkBox) {
    super(checkBox);
    public Component getTableCellEditorComponent(final JTable table, final Object value,
    final boolean isSelected, final int row, final int column) {
    Color background = null;
    background = ColorManager.SELECTED_ROW_BGCOLOR;
    labelVal = (JLabel) value;
    labelVal.setOpaque(true);
    labelVal.setFont(FontManager.TABLE_DATA_FONT);
    labelVal.setBackground(background);
    labelPanel = new JPanel();
    labelPanel.setOpaque(true);
    labelPanel.setBackground(background);
    labelPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    labelPanel.setBorder(new EmptyBorder(5, 0, 0, 0));
    labelPanel.add(labelVal);
    return this.labelPanel;
    public Object getCellEditorValue() {
    return this.labelPanel;
    public class LabelCellRenderer extends DefaultTableCellRenderer {
    public LabelCellRenderer(final int alignment) {
    //setHorizontalAlignment(alignment);
    this.align = alignment;
    public Component getTableCellRendererComponent(final JTable table, final Object value,
    final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    if (value != null) {
    if (value instanceof JLabel) {
    labelVal = (JLabel) value;
    labelVal.setOpaque(true);
    labelVal.setFont(FontManager.TABLE_DATA_FONT);
    labelVal.setBackground(background);
    labelVal.setHorizontalAlignment(this.align);
    labelVal.setBorder(new EmptyBorder(0, LRPADD, 0, LRPADD));
    JPanel panel = new JPanel();
    panel.setOpaque(true);
    panel.setBackground(background);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    panel.setBorder(new EmptyBorder(5, 0, 0, 0));
    panel.add(labelVal);
    return panel;
    return this;
    }

    With more than 30 postings you should know by now how to use the "Code" tags when posting code so the code reatains its original formatting and is therefore more readable.
    There is no need to create a custom editor, here is a simple example.

  • How to use JTable model listener???

    Anyone got idea , how to use table model listener. Can explain in simple example with code?? how to pass back to resultset ??

    Well, your pretty good at asking questions, but not very good at thanking people for the help given to you so I don't think I'll waste too much time helping this time.
    A TableModelListener notifies you when the contents of a cell are changed. So simply take the data from the cell and update your ResultSet. You question is so general I don't know how you expect any more advice than that.

  • How to use JTable with DataBase

    Dear All,
    how can i show a table in a frame that containes a data from a database, then can edit , add and delete some records in the database
    thnx 4 all

    Hi
    I've used below codes for fetching data in JTable.
    try{
               DataRequest = Db.createStatement();
               Results = DataRequest.executeQuery("SELECT * FROM Employee");
               rm = Results.getMetaData();
               col = rm.getColumnCount();  //getColumnCount and store it in integer variable col;
               Vector colNames = new Vector();
               for (int i = 1; i<= col; i++){
                 colNames.addElement(rm.getColumnName(i));
               while(Results.next()){
                    Vector row = new Vector();
                   for(int i = 1; i <= col; i++){
                       row.addElement(Results.getObject(i));
                   data.addElement(row);
               jDataTable.setModel(new DefaultTableModel(data,colNames));
               jDataTable.revalidate();
               Results.close();
            catch (SQLException sql){
                JOptionPane.showMessageDialog(this, "Cannot connect to Database"+sql,"Error", JOptionPane.WARNING_MESSAGE);
            }Hope you satisfied with this code.

  • How to use JTable and database

    how i want to know how to store data into Jtable from the database for the end users.
    any tutorial or example will be helpfull.
    thank you

    my problem is i want to store data that i will get from the database into a JTableThen you problem is with Swing in which case you should be searching the Swing forum for answers. This question has been asked and answered several times. I know I've posted solutions before.

  • How to use/populate JTable in Jdev 3.0 ?

    Is there any tutorial or examples available
    on how to use JTable in JDeveloper 3.0 ?
    After creating business objects project
    and application, what steps do I take to
    a) put a jtable class object into my application ? I have tried creating a
    frame (JFrame) using new\objects\frame, and
    then dragging JTable into the UI, but don't
    know how to connect things from there.
    b). manipulate/populate the grid from there
    using the business objects created
    earlier in the project ?
    The html documentation included with JDev 3 provides some clues on individual key word searches, but does not at all connect the dots. What is needed
    here is a tutorial like some of the others
    included.
    null

    You may find the following steps useful.
    Create an InfoBus form by:
    Select menu File | New...
    Select "InfoBus Data Form" and press OK
    Go through the wizard and create a
    Detail or Master Detail form.
    Be sure to place the detail in a GRID control (last few pages of wizard).
    Then look at the generated code. This form will contain a useful class GridControl which contains a JTable element. Most noteworthy is that the JTable is already hooked up to the data source.
    In particular, the GridControl that is in
    your source has a public method:
    public final JTable getTable()
    This gives you access to the JTable to further customize the way you need.
    Ofcourse there are other tutorials that touch
    on the above, but you won't find a tutorial
    on how to hook up a JTable to a database because we have many more advanced classes
    (InfoSwing: GridControl,...) that do that
    and much more for you. You will be much more
    productive if you rely on the additional InfoSwing components.
    I hope this helps,
    John@Oracle JDeveloper Team http://technet.oracle.com
    null

  • How to use vector in JTable? Please help......

    Hi there
    I can use JTable using object array to manupulate data but it has a limitation of defining number of rows of the array. Alternatively i want to use vector. Anyone help me how to convert to using vector.
    Regards.
    mortoza, Dhaka

    hi,
    you could either use javax.swing.table.DefaultTableModel because this class uses a java.util.Vector for data storage or you could implements your own TableModel by extending javax.swing.table.AbstractTableModel.
    best regards, Michael

  • How to use checkboxes in jtable ?

    I am trying to use checkboxes in
    JTable,I set the property in the jtable column to boolean.The proplem is that i do no know how to use this property in java program.My intension is that,I will have a java form and a java button on it,by clicking the button, i will have to write a code,for example a code that fetches records from a table and displays them on the jtable(on the user interface),when I select the check box corresponding to any row,It should let me either delete or edit that row and this modification has to be reflected to the table in the database. At this time,i can fetch and display but i can not delete or modify any row because I do no know how to use the check box inside the jtable.
    Thank you for your help!

    Multi-post: http://forum.java.sun.com/thread.jspa?threadID=5273661&tstart=0

  • How to use AbstractTableModel in JTable

    hi
    i want how to use AbstractTableModel in Jtable
    plz give code

    Multi-post: http://forum.java.sun.com/thread.jspa?threadID=5273661&tstart=0

  • How to use TableModel ???????

    I'm new to java, please help me
    i have this problem. When i choose the item in the combo box for the first time, i get the selected table, but when i choose the other item in combo box, the previous table is still remain in the panel instead of the new one.
    String sList[] =
    "InformationTechnology",
    "Account",
    "Investment"
    combo = new JComboBox();
    combo.setBounds( 220, 35, 260, 25 );
    panel3.add( combo );
    combo.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    System.out.println("Selected Item = "+(String)combo.getSelectedItem());
    TableDisplay((String)combo.getSelectedItem());=
    try {
    // get column heads
    ResultSetMetaData rsmd = rs.getMetaData();
    for ( int i = 1; i <= rsmd.getColumnCount(); ++i )
    columnHeads.addElement( rsmd.getColumnName( i ) );
    // get row data
    do {
    rows.addElement( getNextRow( rs, rsmd ) );
    } while ( rs.next() );
    // display table with ResultSet contents
    table = new JTable( rows, columnHeads );
    scroller = new JScrollPane(table);
    scroller.setBounds( 220, 70, 260, 100 );
    panel3.add(scroller);
    table.validate();
    catch ( SQLException sqlex ) {
    sqlex.printStackTrace();
    just now got a 'guru' told me to use TableModel, but i search the web already but still stuck in the middle, because i don't know how to use TableModel..............

    liml,
    You code shows table instantiation as:
    // display table with ResultSet contents
    table = new JTable( rows, columnHeads );
    Check that it's in scope, say at class-level, for subsequent manipulations.
    --A                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to use TableSorter class with DefaultTableModel

    Hi Friends
    Please tell me how to use TableSorter Class which is in the Java. Tutorials with DefaultTableModel.
    i saw in a thread there it was given that we have to pass the DefaultTableModel to the TableSorter Class.
    I tried to use like that. But i am getting Error Like Exception occurred during event dispatching:
    I am posting the part of Code where i use the DefaultTableModel
         private void displayavailablity(String selectedAuthor)
                   try
                        Vector columnNames = new Vector();
                        Vector data1 = new Vector();
                        String bname,bauthor,bcategory,bref1,bavail,bid;
                        int bref,mid,num;
                        rs = st.executeQuery("SELECT BId,BName,BAuthorName,BAuthorandPublisher,BCat FROM Books where BAuthorandPublisher='" +selectedAuthor+"'");     
                        ResultSetMetaData md= rs.getMetaData();
                        int columns =md.getColumnCount();
                        String booktblheading[]={"NUMBER","BOOK NAME","AUTHOR","CODE","CATEGORY"};
                        for(int i=1; i<= booktblheading.length;i++)
                             columnNames.addElement(booktblheading[i-1]);
                        while(rs.next())
                             Vector row = new Vector(columns);
                             for(int i=1;i<=columns;i++)
                                  row.addElement(rs.getObject(i));
                             data1.addElement(row);
                             //System.out.println("data is:"+data);
                        ((DefaultTableModel)table.getModel()).setDataVector(data1,columnNames);
                        TableSorter sorter = new TableSorter((DefaultTableModel)table.getModel());
                        rs.close();
                   catch(SQLException ex)
                        System.out.println("ERROR IS HERE");
                        ex.printStackTrace();
         }Please help me on this issue Otherwise Please give me some Sample coding to implement this sorting. with DefaultTableModel
    Thank you for your service
    Cheers
    Jofin

    I don't know about any TableSorter class, but I suppose you mean javax.swing.table.TableRowSorter.
    The TableRowSorter is to be attached to the JTable, not to the data model. Here's a cut'n'paste from the last time I used it:
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    myTable.setRowSorter(sorter);
    And heres from the JDK1.6 documentation:
    TableModel myModel = createMyTableModel();
    JTable table = new JTable(myModel);
    table.setRowSorter(new TableRowSorter(myModel));
    Check out http://java.sun.com/javase/6/docs/api/javax/swing/table/TableRowSorter.html. I find it to be good documentation.

  • Question about using Jtable

    hello eb
    i have this code
    Table_Ecg = new JTable();
    String[] columnNames = {" Num�ro ", " Nom ECG ", " Date de Transfert "};
    aModel = (DefaultTableModel) Table_Ecg.getModel();
    aModel.setColumnIdentifiers(columnNames);          
    Table_Ecg.setModel(aModel);
    String[] number = {" 1 ", " 2", " 3 "};
    String[] name = {" katie", " stefi ", " bom"};
    String[] surname = {" don", " kam ", " youri"};i want to insert number in the first column of the tabel
    i want to insert name in the seconf column of the tabel
    i want to insert surname in the third column of the tabel
    if so know howi can do it please help me
    thanks for eb

    The Swing tutorial on "How to Use Tables" has examples of how to hardcode a 2-dimensional array to build a TableModel.
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.htmlYou can also use the addRow(...) method of the DefaultTableModel to dynamically add rows to a table.

  • How to update Jtable based on itemStateChanged in JComboBox?

    My bad... I originally posted this topic in the Java Programming forum before I found this forum. My apologies.
    Anyway, can someone help me out pls? I need to be able to update my JTable based on the selected item in the combobox. Unfortunately, my JTable doesn't update when I choose another item in the combo box. What am I doing wrong? I've read about TableModels but I'm not quite sure how to use it.
    my code:
    my_constructor()
    JComboBox cbdisease;
    cbdisease = new JComboBox();
    cbdisease.setEditable(false);
    cbdisease.setBounds(30,20,270,25);
    add(cbdisease);
    cbdisease.addActionListener(this);
    cbdisease.addItem("View All");
    //aside from "View All" that was previously added to the combo box
    //get the values from the database to fill the comboBox
    showDiseases();
    cbdisease.addItemListener(new ItemListener()
    public void itemStateChanged(ItemEvent e)
    System.out.println(cbdisease.getSelectedItem());
    displayRules();
    }// end constructor
    method: showDiseases
    connect to DB and get D_Description (column in database)
    display D_Description in combo box
    public void showDiseases()
    Connection conn = null;
    ResultSet rs = null;
    Statement statement = null;
    try {
    // Connect to DB
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql:///dbused",
    "root", "");
    // create a statement, execute query
    statement = conn.createStatement();
    rs = statement.executeQuery("SELECT DISTINCT D_Description FROM disease");
    //place D_Description in combo box
    while(rs.next())
    strDesc = rs.getString("D_Description");
    cbdisease.addItem(strDesc);
    conn.close();
    statement.close();
    } catch (SQLException sqle) {
    sqle.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }//end catch
    }//end showDiseases()
    method: displayRules
    connect to DB and get the rules depending item selected in the combo box
    display the rules in a table
    public void displayRules()
    Connection conn = null;
    ResultSet rs = null;
    Statement statement = null;
    try {
    // Connect to DB
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql:///dbused",
    "root", "");
    // create a statement, execute query
    statement = conn.createStatement();
    if(cbdisease.getSelectedItem().equals("View All"))
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease ORDER BY D_DiseaseCode, D_QuestionCode");
    else //query depends on the item selected in combo box other than "View All"
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease WHERE" + " D_Description = '" +cbdisease.getSelectedItem()+ "' ORDER BY D_DiseaseCode, D_QuestionCode");
    // Convert the result set into an array of Objects
    Object[][] rows = getObjects(rs);
    // These are the column headings displayed in the JTable
    String[] headings = { "Disease Code", "Description", "Question Code", "Question", "Action", "# of Arrows", "Arrow"};
    // Initialize a JTable with the rows of objects and column headings
    rulestable = new JTable(rows, headings);
    // Add the table to a JScrollPane to make it display nicely
    rulesScroll = new JScrollPane(rulestable);
    // Add the scroll pane to the container
    add(rulesScroll);
    rulesScroll.setBounds(30,80,720,380);
    conn.close();
    statement.close();
    } catch (SQLException sqle) {
    //sqle.printStackTrace();
    System.out.println(sqle.getSQLState());
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    }//end displayRules()
    method: getObjects
    public Object[][] getObjects(ResultSet rs) throws SQLException
    // Find out how many columns are in the result set
    ResultSetMetaData metaData = rs.getMetaData();
    final int colCount = metaData.getColumnCount();
    ArrayList rows = new ArrayList();
    Object[] row = null;
    while (rs.next()) {
    // for each row in the result set, put every column into a temporary Object array
    row = new Object[colCount];
    for (int a = 0; a < colCount; a++)
    row[a] = rs.getObject(a+1);
    // add the temporary Object array to the array list
    rows.add(row);
    // convert the array list to objects
    return (Object[][])rows.toArray(new Object[0][0]);
    }//end getObjects()

    Just pass the new data to a new TableModel object's
    constructor and then u can use this new table model in
    ur JTable constructor. that woud automatically update
    the table data.
    Cheers!
    Asimsir Asim, do you mean inserting
    DefaultTableModel rulesmodel = new DefaultTableModel(rows, headings);
    to my code?
    public void displayRules()
    Connection conn = null;
    ResultSet rs = null;
    Statement statement = null;
    try {
    // Connect to DB
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql:///dbused",
    "root", "");
    // create a statement, execute query
    statement = conn.createStatement();
    if(cbdisease.getSelectedItem().equals("View All"))
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease ORDER BY D_DiseaseCode, D_QuestionCode");
    else //query depends on the item selected in combo box other than "View All"
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease WHERE" + " D_Description = '" +cbdisease.getSelectedItem()+ "' ORDER BY D_DiseaseCode, D_QuestionCode");
    // Convert the result set into an array of Objects
    Object[][] rows = getObjects(rs);
    // These are the column headings displayed in the JTable
    String[] headings = { "Disease Code", "Description", "Question Code", "Question", "Action", "# of Arrows", "Arrow"};
    // Initialize a JTable with the rows of objects and column headings
    rulestable = new JTable(rows, headings);
    // Add the table to a JScrollPane to make it display nicely
    rulesScroll = new JScrollPane(rulestable);
    // Add the scroll pane to the container
    add(rulesScroll);
    rulesScroll.setBounds(30,80,720,380);
    conn.close();
    statement.close();
    DefaultTableModel rulesmodel = new DefaultTableModel(rows, headings); //like this?
    rulestable.setModel(rulesmodel);     
    } catch (SQLException sqle) {
    //sqle.printStackTrace();
    System.out.println(sqle.getSQLState());
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    }//end displayRules()

  • How i use multi panel in single applet

    hi master
    sir i need three panel in single applet
    i use this code but not set the panel
    pnl.setBounds(20, 10, 10, 20);
    and
    pnl.setLocation(12, 12);
    and
    pnl.setSize(12, 20);
    this is my class code
    JTable table = new JTable(rdata, columnNames);
    getContentPane().add(table.getTableHeader(),BorderLayout.NORTH);
    getContentPane().add(table);
    JPanel pnl = new JPanel();
    //pnl.setBounds(20, 10, 10, 20);
    //pnl.setLocation(12, 12);
    pnl.setSize(12, 20);
    pnl.add(new JScrollPane(table));
    getContentPane().add(pnl);
    //pnl.setBounds(10, 10, 10, 20);
    please sir give me idea how i use multi panel and how i set panel boundry
    thanking you
    aamir

    http://forum.java.sun.com/thread.jspa?threadID=5118094&tstart=0

  • How i use java applet data grid i have many record i need show in grid

    hi master
    sir i have many record i want show all record in applet grid how i use grid in applet
    please send me sample code of java class how send many record to grid and applet code how use applet grid
    thanks
    aamir

    Duplicate post:
    how use the jtable in java applete
    Aamir,
    If you use JApplet then you can use JTable. Just do an Internet search for "JTable" and "applet".
    Good Luck,
    Avi.

Maybe you are looking for

  • File to RFC/BAPI - Async- How to capture response field value

    Hi, I am doing File to RFC/BAPI Scenario. I have Two BAPI's. THe same source xml file is mapped to the Two Target BAPI's. For the first flow i.e File to BAPI1, I need to capture BAPI Response, field value and pass this value as Input to the BAPI2. Ho

  • Tax code AA related issue

    Hi All, I am facing an issue while posting a customer invoice. It is displaying an error msg " Tax code AA does not appear in any G/L account item." Please advise what to do Thanks in advance, Sasidhar

  • HP printers won't work with windows 7

    I have two HP printers a laserjet 1200 series and Photosmart C5540 all in one. I can print single pages ONLY on the 1200.  If i try to print multiple pages all I get page after page with a single line of hyrogliphics.  I don't know if I spelled that

  • Media Encoder Freezing Up Mac When Exporting

    Hello, Not sure if this has started due to a recent Media Encoder update or from the fact that I've switched out my hard drive for a SSD model. It seems that now I can no longer use my Macbook Pro do do email or browse the web when exporting a video

  • ICloud photo library question

    So I can find hundreds of articles telling me that if you iCloud storage is full, your photos won't sync anymore. But if you have thousands of  photos, what will happen in my phone is eventually full? I mean, I have my "optimize iPhone storage" optio