About focu in a JTable

Hi,
Is it possible to make a column of a JTable not focusable ? How?
Thanks
Stephen

Hi,
int colIndx = jTable2.getColumnModel().getColumnIndex("LastName");
jTable2.getColumnModel().getColumn(colIndx).setCellRenderer(new MyTableCellRenderer());
class MyTableCellRenderer implements TableCellRenderer{
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row, int column) {
JTextPane colRenderer = new JTextPane();
colRenderer.setText((String)value);
colRenderer.setFocusable(false);
return colRenderer ;
Frank

Similar Messages

  • About row selection in JTable

    This is also a question about JTable, when type the key "ENTER", the row selection will focus on the next line, how can I stop this default action? Can I make the default action of pressing "ENTER" to be activate a cell in the JTable to editing state?
    Thanks for any help.

    Sorry, I need to ask for help again, yes, in your case, the method works,
    but I am afraid this method does not help me, because I don't know HOW TO MAKE THE F2 FUNCTION in my case.
    I use the method you recommend, and yes I can stop the default response of pressing ENTER, it means when I stroke ENTER in my table, the selection won't go to the next line, but it just up to my half purpose, how can I use Enter to editing a cell then? My silly question is I even don't know how to make F2 works?

  • About JCheckBox in a JTable.

    Hi,
    In my JTable, one of the column uses checkbox as cell editor.
    I like to know how to get the row index of the row where the clicked checkbox is in.
    Thanks
    Stephen

    Hi,
    TableColumnModel tcm = jTable1.getColumnModel();
    JUTableLOVEditor jTableLOVEditor = (JUTableLOVEditor) tcm.getColumn(0).getCellEditor();
    JComboBox component = (JComboBox) jTableLOVEditor.getComponent();
    component.addFocusListener(new FocusListener(){
    public void focusGained(FocusEvent e) {
    DCIteratorBinding dciter = (DCIteratorBinding)panelBinding.get("EmployeesView1Iterator");
    System.out.println(dciter.getCurrentRowIndexInRange());
    public void focusLost(FocusEvent e) {
    Frank

  • Question about GUI Design on JTable and its separate editor

    Hi all,
    I need to use JTable with separate editor , that way when I double click one of the JTable's row its editor will popup in another window.
    Based on GUI design principles, where should I put the editor, in another tab panel or a JDialog ?
    Any advice would be greatly appreciated.
    Regards,
    Setya

    if you dont have to edit a lot of fields, this will
    be a good solution.
    but if you have many fields, it would be a good thing
    to put a JTabbedPane into the under
    JSplitPane-container ... or to use a JDialog :)Yes, that's the only problem I can think of, if the fields are too many.
    But then, if I have so many fields in one form. I won't put them in a JTable because users will find it cumbersome for having to scroll left and right to see those fields. I believe on this scenario JTable is just not the right component to use.
    Regards,
    Setya

  • Double click in a JTable row

    Hi,
    I have the following problem. I would like to have a JTable with single selection (this is ok so far), but I would like it to have the following behaviour.
    If a row is clicked, it becomes selected. If a selected row is clicked again it becomes deselected.
    Does anyone have any suggestions?
    Thnx,
    G

    I am writing about JTree rather than JTable ... because there are no other replies I figured it's better than nothing ...
    This code does the behavior you describe to a JTree.
    (Code snippet copied from JTree javadoc page and modified by me.)
    java.awt.event.MouseListener ml = new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent e) {
    int selRow = tree.getRowForLocation(e.getX(), e.getY());
    if(selRow != -1) {
    if(e.getClickCount() == 1) {
    System.out.println("SINGLE CLICK");
    else if(e.getClickCount() == 2) {
    System.out.println("DOUBLE CLICK");
    tree.clearSelection();
    tree.addMouseListener(ml);
    I put the print statements in to demonstrate that a double-click event actually is a single-click followed by a double-click. Since you didn't sound like you need to do any custom code for the single-click case, this fact probably doesn't affect you.
    I hope I helped
    Mel

  • Passing TableModel to a JTable

    <b>I created a personal tableModel class.
    I called it with that code :</b>
    tableModels[0]=new MyTableModel(data1);
    <b>and any time I have this exception:</b>
    Exception in thread "main" java.lang.NullPointerException:
    at MyTableModel.getRowCount(MyTableModel.java:25)
    at javax.swing.table.DefaultTableModel.setNumRows(DefaultTableModel.java
    :317)
    at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:105
    at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:70)
    at MyTableModel.<init>(MyTableModel.java:11)
    at SwingWinc.layoutComponents(SwingWinc.java, Compiled Code)
    at SwingWinc.buildGUI(SwingWinc.java:194)
    at SwingWinc.<init>(SwingWinc.java, Compiled Code)
    at SwingWinc.main(SwingWinc.java:504)
    <b>Why ? please help.
    Follow the MyTableModel class </b>
    import javax.swing.table.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    public class MyTableModel extends DefaultTableModel
    final String[] columnNames={"Analisi Eseguite","Risultati","Valori di riferimento"};
    Object[][] matrixTable={
    {"GLICEMIA","150 mg/dl","( 60-110 mg/dl )"},
    {"AZOTEMIA","33 mg/dl","( 20- 50 mg/dl )"},
    {"COLESTEROLO TOT","291 mg/dl","( 130-200 mg/dl )"},
    {"COLESTEROLO HDL"," 60 mg/dl","( 40- 70 mg/dl )"},
    {"COLESTEROLO LDL","100 mg/dl","( 0-150 mg/dl )"},
    {"Glicemia","88 mg/dl","( 60-110 mg/dl )"},
    {"Glicemia","88 mg/dl","( 60-110 mg/dl )"},
    {"Glicemia","88 mg/dl","( 60-110 mg/dl )"},
    {"Glicemia","88 mg/dl","( 60-110 mg/dl )"},
    {"Glicemia","88 mg/dl","( 60-110 mg/dl )"},
    {"Glicemia","88 mg/dl","( 60-110 mg/dl )"}} ;;
    public MyTableModel(Object [][] matrix)
    DefaultTableModel tableModel=new DefaultTableModel(matrix,columnNames);
    matrixTable=matrix;
    public int getColumnCount()
    return columnNames.length;
    public int getRowCount()
    return matrixTable.length;
    public String getColumnName(int col)
    return columnNames[col];
    public Object getValueAt(int row, int col)
    return matrixTable[row][col];
    public Class getColumnClass(int c) {
    return getValueAt(0, c).getClass();
    public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    if (col < 2) {
    return false;
    } else {
    return true;
    public void setValueAt(Object value, int row, int col)
    matrixTable[row][col] = value;
    fireTableCellUpdated(row, col);
    I called it with that
    tableModels=new MyTableModel(data1);

    Hi,
    is that data1 reference, that you pass, initialized or do you pass perhaps a null-reference there?
    Another thing - in your constructor, you never call the super-constructor in order to construct the underlying DefaultTableModel in the correct way. Instead you instantiate a new DefaultTableModel with your parameters, that will exist only in this block and so do really nothing usefull.
    The normal way to call the super-constructor is in your case:
    public MyTableModel(Object [ ] [ ] matrix) {
    super(matrix,columnNames);
    tableMatrix=matrix; } // see comments belowAlso it is not correct, to hold an own matrixTable within the DefaultTableModel and overwrite the TableModel interface methods - the DefaultTableModel has an own Vector of Vector structure to hold the table-data - if you pass for example an Object [ ] [ ] in its constructor, the DefaultTableModel builds its dataVector right after it and copy the values for this array into the dataVector.
    If you want to use your own datamodel in Object [ ] [ ] form, then I would suggest to make your MyTableModel extend AbstractTableModel - but if you want to use DefaultTableModel and its methods, you should leave the storage of the data to the DefaultTableModel and its dataVector,
    that uses a Vector, that contains Vectors, that each contain the celldata of one row. The methods of DefaultTableModel are designed to use that dataVector, they will not work with or even use your matrixTable array, except that the original data is copied into the dataVector, if you change the constructor in the way, I have posted above.
    So my advice is, to consult the online tutorial for that - it is really good and you will see, that creating an own TableModel by subclassing AbstractTableModel is relative easy to do. You have the basic steps done in your implementation (if it would be no DefaultTableModel, that would be a good start for that). So, I guess, you will figure it out, If you read the tutorial about the use of JTable. Start here:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    greetings Marsian

  • Is it possible to temporarily disable JTable ?

    I have a JTable that is used to set parameters of a midi sequence that is to be played. When I then start the sequence, the timing is very bad, and I have reason to believe that the constant updating of the JTable is partly to blame. As my data is in the table model, I guess I could destroy the JTable to play the sequence, but I would prefer to leave the JTable view visible (even if unresponsive), while the sequence plays. Is there any way to temporarily 'disable' a JTable?
    Thanks, Scott

    Hi Darryl- my JTable gets its data from a class which extends AbstractTableModel, and I put the System.out... code in the getValueAt() method of that class. It it seems like the calls to refresh the JTable are internal and not due to my programming (but I will definitely not rule out the possibility that my code is faulty... I might have a fireDataChanged() where it shouldn't be...).
    It has been suggested to me before to include a SSCCE, but I think I'd have to include most of my program because most of the classes use each other... listeners, etc. I've probably written spaghetti code.
    Do you happen to know about how often a JTable normally updates itself? Aside from this most recent experiment of mine, I have the impression (from internet searches, etc.) that the JTable's normal behavior is to continuously update itself.
    I don't mean to confuse what it is I am needing help with, but this has been a specific question relating to a larger problem I'm having - which you may recognize as you have been replying to my other posts as well. I have thought that 'putting the JTable to sleep' might be a patch to get my program to work properly, but I've suspected that there really was an underlying problem, that is, that my sequencer thread priority was not high enough. With the NetBeans debugger I found the following:
    Swing-Shell - 6
    TimerQue -5
    Java 2D Disposer -10
    Attach Listener -5
    Signal Dispatcher -9
    Finalizer - 8
    Reference Handler - 10
    Java Sound Sequencer -8 // this is the thread that I'm most interested in - it plays the sequence
    So I am wondering that if I change these priorities to be more favorable for the sequencer thread, that it might not even matter what the JTable does (although if I have some sort of unintended loop in my code, I need to fix that). I would prefer to have the JTable 'active', for it displays the current beat of the sequencer, and similar real-time info.
    I apologize for including this 'stream of consciousness, post, I hope it is not to hard to follow. But at this point I think I'll try to get my priorities straght (ugh!!!) and hopefully I can leave the JTable as it is.
    Thanks, Scott

  • Add/delete row in JTable

    I went through the tutorial of JDK about how to programming JTable, i can NOT find a way to add/delete row into/from JTable.
    I immagine it would be a difficult task because the data set it takes 'Object data[][]' is NOT dynamically grow/shrinkble.
    Can we make it take ArrayList[] as input dataset so that the dataset can dynamically grow/shrink?
    Any other way around to add/delete row?
    THANKS for your consideration.

    You have to write your own TableModel like extending AbstractTableModel. In that class add custom methods to add and remove rows. From those methods call fireTableRowsDeleted(..) and fireTableRowsInserted(..) to update UI.

  • Urgent: Repaint, JTable, JPanel...

    I know there've been a few posts about using repaint() for JTable...but my layout's a bit different than the ones already mentioned and trying to update my table is driving me crazy...
    i have a table class which extends a JPanel...
    an instance of this is created in a separate class within a JPanel...THIS Panel is inside a scrollpane (the table itself isn't)...this class has a button, on the click of which the table needs to be updated.
    Now, should i be repainting the table, the table's panel, the parent panel, or the scrollpane? Or should i be doing something compeltely different?
    PLEASE HELP!

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

  • Populating a hash table

    Hi,
    I have a hashtable which contains a number of objects of my custom class.
    I need the properties of these objects to be stored in a jTable, a row per object.
    Could anyone offer me any help,
    Anything will be very much apreciated

    The title of your post is "populating a hash table" but the first sentence suggests you have already populated the hash table and you want to get data out of it.
    The elements() method gives you an Enumeration that allows you to extract the values from the Hashtable.
    There's a tutorial here about how to use JTables: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

  • Java MYSQL count problem

    Hi all,
    I'm a newbie in developer world..Currently i'm developing a system and stuck when i want to make the count function..i'm wondering if i can make a count statement from the java programming or from the mysql statement..Below is my prob..
    In mysql db,i store the record as below..
    person ID Diet
    1 A
    1 B
    2 A
    3 A
    3 C
    4 A
    4 B
    4 C
    while in jtable,i display it as below..each diet are separated by comma
    Person ID Diet
    1 A,B
    2 A
    3 A,C
    4 A,B,C
    5 A,B
    6 B,C
    7 A
    8 A,B
    9 B,C
    10 B
    And i need an output like below..
    Diet Count(persons)
    A,B 3
    A 2
    A,C 1
    A,B,C 1
    B,C 2
    B 1
    Really need ur guys help..as i've no idea on how to solve this..
    Thanx in advance!

    Thanx psyber for your reply..
    Yup..i want to count the number of person who got certain Diet.
    It will be easier if i'm counting a single diet, but my problem now is i want to count the number of person with certain Diet combination.
    How about counting from the jtable? I've been able to display the record in a table,with comma separator..
    id diet
    1 a,b
    2 a
    3 a,b,c
    4 b
    5 a,b
    n i need the output to be like this
    diet Count(Person)
    a,b 2
    a 1
    a,b,c 1
    b 1
    is it possible?
    thanx again!

  • JFrame Resize issue

    Allo all.
    I have a GUI that uses one JFrame and contains a Box layout of GridLayout and BoxLayout JPanels.
    I have set Max, Min and Pref sizes for all the JPanels, which works perfectly, the Frame wont get smaller than the minimum size, and it loads at the preffered size.
    However, expanding past the Max sizes leaves the components stranded top and center of the frame, with plenty of unwanted empty space.
    Setting the JFrames max, min and pref sizes completely ruins all the others, allowing resizing to 0,0 size and full screen.
    Any ideas? A quick look showed that I'd be able to extend JTable and do it that way some how, but I wasn't sure on the exact things I'd have to override.
    Java 1.5 , and I know a fair bit about Java.

    Extending the JTable class in order to solve layout problems is NOT THE WAY!!
    You'd be asking for more trouble than you already have. Instead, consider using a combination of a GridBagLayout and some RigidArea
    Box.createRigidArea(Dimension d] ,and perhaps some Glue- or Strut-components:
    Box.createHorizontalGlue()
    Box.createStrut(int width)
    [ /code]
    That should solve many layout issues....
    dealing with GUI's ==  puzzeling around with layoutmanagers and components                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can You Help Me ABout getSelectedRow in JTable

    Can you help me on how to solve my problem about the getSelectedRow .....
    I have one JComboBox and a SearchButton
    ... Once I selected an Item in a JComboBox, I will press the SearchButton
    and then it will look up to the database and display it in the JTable..........
    i used the getSelectedRow to print the value that I selected in the table...
    like this...
    public void mouseClicked(MouseEvent e) {
    // Ilabas yung form
    if(e.getClickCount() == 1 ) {
    System.out.println(table1.getSelectedRow());
    In the first press in the SearchButton and then clicking the row
    , It will print the selected row...... but when i press again the SearchButton then clicking a row again........
    there is a problem occured....... selectedRow is always -1, can you help me to solve this.....

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.util.*;
    import javax.swing.plaf.metal.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.text.*;
    import java.beans.*;
    public class OpenProject extends JDialog {
         ResultSet rs, rs1, rs2, rs3;
         JFrame JFParentFrame; // create a JFrame
         JFrame OwnerFrame; // create a JFrame
         public JLabel proj_name;
         public JLabel proj = new JLabel("Project Name:");
         public JLabel form = new JLabel("Form Name");
         public JLabel lang = new JLabel("Language");
         public JComboBox form_lang = new JComboBox();
         public JComboBox form_name = new JComboBox();
         public JButton edit = new JButton("Edit");
         public JButton reload = new JButton("Search");
         public JButton def = new JButton("Set Text Default");
         public JButton langs = new JButton("Add Language");
         public JButton exit = new JButton("Exit");
         public JPanel panel1 = new JPanel ();
         public JTable table1, table2, table3,table4;
         public JScrollPane scrollPane1, scrollPane2, scrollPane3, scrollPane4;
         public JTabbedPane UITab,UITab1;
         Container c = getContentPane();
         Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
         public String column[][];
         public String strRow;
         public String strCol;
         public String strForm;
         public String strGetProj_id;
         public String strForm_lang;
         public String strForm_name;
         private boolean DEBUG = false;
         public int getLang;
         public int getForm;
         public int getDef_id;
         public int count2 = 0,count3 = 0,count4 = 0;
         public int row2 = 0,row3 = 0,row4 = 0;
         public int selectedRow1 = 0, selectedRow2 = 0;
         public DbBean db = new DbBean();
         public OpenProject(JFrame OwnerForm, String getProj_id) {
              super(OwnerForm,true);
                   strGetProj_id = getProj_id;
              try{
                   db.connect();
              } catch(SQLException sqlex) {
              } catch(ClassNotFoundException cnfex) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch(Exception e) {
              // Para ito sa paglalagay sa dalawang combo box ng value.......
              try {
                   rs = db.execSQL("Select * from mst_form where form_proj_id = "+strGetProj_id+"");
                   while(rs.next()) {
                        form_name.addItem(rs.getString("form_name"));
                        //System.out.println(strForm);
              } catch(SQLException sqlex) {
              try {
                   rs = db.execSQL("Select distinct from mst_form where form_proj_id = "+strGetProj_id+"");
                   while(rs.next()) {
                        form_name.addItem(rs.getString("form_name"));
                        //System.out.println(strForm);
              } catch(SQLException sqlex) {
              try {
                   int counts;
                   rs = db.execSQL("Select * from mst_project where proj_id = "+strGetProj_id+"");
                   while(rs.next()) {
                        counts = rs.getInt("proj_lang_id");
                        System.out.println(counts);
                        rs1 = db.execSQL("Select * from mst_language where lang_id = "+counts+"");
                        while (rs1.next()) {
                             form_lang.addItem(rs1.getString("lang_name"));     
              } catch(SQLException sqlex) {
              edit.setActionCommand("edit");
              edit.addActionListener(actions);
              reload.setActionCommand("load");
              reload.addActionListener(actions);
              def.setActionCommand("default");
              def.addActionListener(actions);
              langs.setActionCommand("lang");
              langs.addActionListener(actions);
              exit.setActionCommand("exit");
              exit.addActionListener(actions);
              proj_name = new JLabel();     
              proj_name.setBackground(new Color(255,255,255));
              form_name.setMaximumRowCount(5);
              form_name.setBackground(new Color(255,255,255));
              form_lang.setMaximumRowCount(5);
              form_lang.setBackground(new Color(255,255,255));
              proj.setBounds(20, 20,100,20);
              proj_name.setBounds(120, 20,250,20);
              form.setBounds(20, 50,100,20);
              form_name.setBounds(120, 50,150,20);
              lang.setBounds(300, 50,100,20);     
              form_lang.setBounds(380, 50,150,20);
              reload.setBounds(560,50,80, 20);
              edit.setBounds(110,360,115,20);
              def.setBounds(230,360,115,20);
              langs.setBounds(350,360,115,20);
              exit.setBounds(470,360,115,20);
              panel1.add(getTable());
              panel1.setLayout(null);     
              panel1.setBackground(Color.white);     
              panel1.add(proj);
              panel1.add(proj_name);
              panel1.add(form);
              panel1.add(form_name);
              panel1.add(lang);
              panel1.add(form_lang);
              panel1.add(reload);     
              panel1.add(def);
              panel1.add(langs);
              panel1.add(exit);
              panel1.add(edit);
              c.add(panel1);
              setSize(680,420);
              setTitle("Open Project");
              setLocation((screen.width - 590)/2,((screen.height - 280)/2) - 45);
         public JTabbedPane getTable() {
              UITab = new JTabbedPane();
              strForm_lang = form_lang.getSelectedItem().toString();
              strForm_name = form_name.getSelectedItem().toString();
              int count1=0;
              int row1=0;
              try {
                   rs = db.execSQL("Select * from mst_default where def_proj_id = '"+strGetProj_id+"' AND def_category = 'Title'" );
                   while(rs.next()) {
                        count1 += 1;
                        getDef_id = rs.getInt("def_id");
                   column = new String[count1][2];
                   rs1 = db.execSQL("Select form_id from mst_form WHERE form_name = '"+strForm_name+"'");
                   while(rs1.next()) {
                        getForm = rs1.getInt("form_id");
                        System.out.println("getForm");
                   rs2 = db.execSQL("Select lang_id from mst_language WHERE lang_name = '"+strForm_lang+"'");
                   while(rs2.next()) {
                        getLang = rs2.getInt("lang_id");
                        System.out.println("getLang");
                   rs3 = db.execSQL("Select * from mst_default a, mst_translation b WHERE a.def_form_id = '"+getForm+"' AND b.trans_lang_id = '"+getLang+"' AND a.def_proj_id = '"+strGetProj_id+"' AND b.trans_def_id = '"+getDef_id+"' AND a.def_category = 'Title' " );
                   while(rs3.next()) {
                        column[row1][0] = "" + rs3.getString("display_name");          // rowNum ay kung ilan ang row na ilalabas
                   column[row1][1] = "" + rs3.getString("translation"); // Default yung isang array ng column ko, kaya fixed
                        row1++;
                   row1 = 0;
              } catch(SQLException sqlex) {
                   sqlex.printStackTrace();
                   System.exit(1);
              // End
              table1 = new JTable(new MyTableModel()){
              scrollPane1 = new JScrollPane(table1);
              UITab.setBounds(30,100,610,250);
              UITab.add("Title",scrollPane1);
              return UITab;
         class MyTableModel extends AbstractTableModel {     
                   // Pagawa ng header Coloumn
                   String ColumnHeaderName[] = {
                        "Default Text",""+strForm_lang+" Translation"
                   //End
                   public int getColumnCount() {     
                        //System.out.println("The Column Count is" + ColumnHeaderName.length);
         return ColumnHeaderName.length;
         public int getRowCount() {
              //System.out.println("The Row Count is" + column.length);
         return column.length;
         public String getColumnName(int col) {
                        //System.out.println("The Column Name is" + ColumnHeaderName[col]);     
         return ColumnHeaderName[col];
         public Object getValueAt(int row,int col) {
              System.out.println("The value at row and column = " + column[row][col]);
         return column[row][col];
         public int getSelectedRow() {
              System.out.println("Integer" + column.length);
              return column.length;
         ActionListener actions = new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                   String source = ae.getActionCommand();
                   if (source == "load") {
                        table1.clearSelection();
                        panel1.add(getTable());
                        table1.addNotify();
                        repaint();
                   } else if (source == "default") {
                        dispose();
                        TextDefaultForm form = new TextDefaultForm(OwnerFrame,JFParentFrame);
                        form.setVisible(true);
                   } else if (source == "lang") {
                        dispose();
                        CreateProject lang = new CreateProject(JFParentFrame);
                        lang.setVisible(true);
                   } else if (source == "exit") {
                        dispose();
                   } else if (source == "edit") {
                        if (table1.getValueAt(table1.getSelectedRow(),table1.getSelectedColumn()) != null){
                             formLang lang = new formLang(OwnerFrame,strCol,strRow, strGetProj_id);
                             lang.setVisible(true);
         MouseListener MouseTableListener = new MouseListener() {
                   public void mouseClicked(MouseEvent e) {
                        // Ilabas yung form
                        if(e.getClickCount() == 2 ) {
                             dispose();
                             int col_a = 0;
                             int col_b = 1;
                             selectedRow1 = table1.getSelectedRow();     
                             Object objColumn1 = table1.getValueAt(selectedRow1, col_a);
                             Object objRow1 = table1.getValueAt(selectedRow1, col_b);
                             strCol = objColumn1.toString();
                             strRow = objRow1.toString();
                             formLang lang = new formLang(OwnerFrame,strCol,strRow,strGetProj_id);
                             System.out.println(selectedRow1);
                             System.out.println(strCol);
                             System.out.println(strRow);
                             lang.txtProj.setText(strCol);
                             lang.txtLang.setText(strRow);
                             lang.show();
                        } else if (e.getClickCount() == 1) {
                             table1.setSelectionBackground(Color.blue);
                             table1.setColumnSelectionAllowed(false);
                        table1.setRowSelectionAllowed(true);
                        table1.setFocusable(true);
                             int a = table1.getRowCount();
                             System.out.println("Row Count = " + a);
                             int sel = table1.getSelectedRow();     
                             //if (sel == -1) return;
                             System.out.println("Selected Row = " + sel);
                             System.out.println(table1.isRowSelected(sel));
                   public void mouseReleased(MouseEvent e) {
                   public void mouseExited(MouseEvent e) {
                   public void mouseEntered(MouseEvent e) {
                   public void mousePressed(MouseEvent e) {
         //public static void main(String leo[]) {
              //OpenProject open = new OpenProject();
    }

  • A question about JTable .setValueAt(...)

    hi, I write some code which use the Table to represent the data fetched from MS-ACCESS.
    the problem is about the UpdateObject(...) method which is in the implement of the AbstractTableModel method setAtValue(). when transfered OBJECT TYPE is java.lang.String, I can't get the correct result in the JTable view.
    by the way, I use java2SE 6 Beta version
    my code is as below, could somebody point me out my problem
    public class MyTableModel extends AbstractTableModel {
        private ResultSet rs ;
        private ResultSetMetaData rsmd;
        /** Creates a new instance of MyTableModel */
        public MyTableModel() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            String url = "jdbc:odbc:CoffeeBreak";
            try {
                Connection con = DriverManager.getConnection(url,"","");
                String strSQL = "SELECT * FROM COFFEES";
                Statement pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                rs = pSt.executeQuery(strSQL);
                rsmd = rs.getMetaData();
            } catch (SQLException ex) {
                ex.printStackTrace();
    /* table model retrieve the Class type of a column method here*/
    public Class getColumnClass(int c){
            try {
                return Class.forName(rsmd.getColumnClassName(c+1));
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return String.class;
    //method of update database and JTable after user edited a table cell
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            try {
                int concurrency = rs.getConcurrency();
                if(concurrency == 1008){
                    rs.absolute(rowIndex+1);    //the JTable row index is start from 0,so plus 1
                    rs.updateObject(columnIndex+1, aValue);//the JTable column index is start from 0, so plus 1
                    rs.updateRow();
            } catch (SQLException ex) {
                ex.printStackTrace();
        } when the column type is about java.lang.String, the cell's result is incorrect, it looks like "[B@1f8f72f" and database can't update.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Yes, I have implemented them all.
    I paste them all now. thank all here, first.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.AbstractTableModel;
    * @author qhj
    public class MyTableModel extends AbstractTableModel {
        /** Creates a new instance of MyTableModel */
        private ResultSet rs ;
        private ResultSetMetaData rsmd;
        public MyTableModel() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            String url = "jdbc:odbc:CoffeeBreak";
            try {
                Connection con = DriverManager.getConnection(url,"","");
                String strSQL = "SELECT * FROM COFFEES";
                Statement pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                rs = pSt.executeQuery(strSQL);
                rsmd = rs.getMetaData();
            } catch (SQLException ex) {
                ex.printStackTrace();
        public int getRowCount() {
            try {
                rs.last();
                return rs.getRow();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return 0;
        public int getColumnCount() {
            try {
                return rsmd.getColumnCount();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return 0;
        public Object getValueAt(int rowIndex, int columnIndex) {
            try {
                rs.absolute(rowIndex+1);
                return rs.getObject(columnIndex+1);
            } catch (SQLException ex) {
                ex.printStackTrace();
            return null;
        public String getColumnName(int column){
            try {
                return rsmd.getColumnName(column+1);
            } catch (SQLException ex) {
                ex.printStackTrace();
            return "N/A";
        public Class getColumnClass(int c){
            try {
                return Class.forName(rsmd.getColumnClassName(c+1));
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return String.class;
        public boolean isCellEditable(int row, int col) {
            //Note that the data/cell address is constant,
            //no matter where the cell appears onscreen.
            return true;
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            try {
                int concurrency = rs.getConcurrency();
                if(concurrency == 1008){
                    rs.absolute(rowIndex+1);
                    rs.updateObject(columnIndex+1, aValue);
                    rs.updateRow();
            } catch (SQLException ex) {
                ex.printStackTrace();
            fireTableDataChanged();
    }

  • Question about JTable...

    Hi people,
    I have a question about class JTable of Java and how can i add dynamic content to it. More specific i would like
    to create a table which has a dynamic content at its rows and columns (etc i will use a method which will generate
    dates of 1/02/05 to 1/03/05 format and i will add them as titles in the row section of my table and in the column
    section i will add times of the day divided in quarters like 00.00 00.15 00.30 00.45..... just like a calendar) Any ideas????

    Use the DefaultTableModel. It has addRow and addColumn methods.

Maybe you are looking for

  • How to schedule job?

    Hello All, i have a few questions about jobs (scheduling jobs) I want to run one procedure at 7:00 A.M and I want to stop this procedure at 12:30 PM on Daily basis.Is it possible with DBMS_JOB? I don't know how to stop running job at specified time.

  • Wrong path in address server?

    Hi, i have a DS3 installation in "E:\BO\Data Services". If I start a Batch Job which uses a Germany Address Cleanse transform I get an error that the file "C:/Programme/Business Objects/BusinessObjects Data Services/DataQuality\reference_data\ga_coun

  • H.264 mov to Flash

    Adobe says Flash now "supports H.264 encoding". Since this encoding is QuickTime engine (ISO standard), how do I get an H.264-compressed MOV file to play in Flash Player? (e.g "import to Flash, export as FLV" or some such). Thanks in advance.

  • Blank first page on DHTML viewer in Crystal 2008

    I have seen some threads regarding this issue but no real resolution. We are using Crystal 2008 running in a Windows 2003 web server and IIS 6. With the base version of Crystal 2008 installed, everything worked fine when rendering reports in the DHTM

  • Finding hidden arrors...

    What should be approach to finding hidden errors in ABAP programs ? Points will be awarded. Tushar.