JTable renderering/binding

I have a couple questions:
1. I need to put buttons in some of the cells... add/copy/delete that particular row. how do you track what row button was clicked? so i can access that data in my tablemodel and update the db.
2. how do you bind jtable editable fields? for example, in another project i had a jdialog, and i binded all jtextfields to my domain objects, and when anything changed it enabled a save button below (worked really well!). How can i do that with jtable?
Please ask to clarify if neccessary.

The v6 of NetBeans supports the new jsr 295 for beans
binding. This version is not final yet, though:
http://www.netbeans.org/community/releases/60/index.ht
ml
http://www.netbeans.org/download/flash/netbeans_6_gui_
builder/netbeans_6_gui_builder.html
-PuceThanks puce, yeah I read a lot of good things about JSR295, and I'm glad their moving towards integrating binding into swing, it's a key component to desktop applications.
But my question isn't necessarily the technology for binding, but instead from a design point of view.

Similar Messages

  • How to select rows in the inner JTable rendered in an outer JTable cell

    I have wrriten the following code for creating cell specific renderer - JTable rendered in a cell of a JTable.
    table=new JTable(data,columnNames)
    public TableCellRenderer getCellRenderer(int row, int column)
    if ((row == 0) && (column == 0))
    return new ColorRenderer();
    else if((row == 1) && (column == 0))
    return new ColorRenderer1();
    else
    return super.getCellRenderer(row, column);
    ColorRenderer and ColorRenderer1 are two inner classes, which implement TableCellRenderer to draw inner JTable on the outer JTable cell, having 2 rows and 1 column each.
    Now what is happening the above code keeps executing continously, that is the classes are being initialised continously, inner JTables are rendered (drawn) continously, and this makes the application slow after some time. It throws java.lang.OutOfMemoryException.
    WHY IS IT SO??? I can't understand where's the bug..
    Any advice please???
    Moreover i want selections in inner tables and not on outer table, how can this be possible.
    I am working on this since a long time but have not yet found a way out...

    With your help i have overcome the problem of continous repeatition.
    The major problem which I am facing is, in selecting rows in the inner rendered JTables.
    I have added listener on outer JTable which select rows on the outer JTable, hence the complete inner JTable which being treated as a row, gets selected.
    The thing is i need to select the rows of inner rendered JTables,not the outer JTable.
    How to go about it??
    I have even added listener to inner rendered JTables, but only first row of every table gets selected.
    Please help....
    Thanks in advance.

  • Jtable Renderer Problem

    Hi
    I have Jtable table where i am setting the model by using TableModelSorter model (extending defaulttablemodel), this table moedel is used for sorting.
    tblDocs.setModel(new TableModelSorter(modelDocument,tblDocs.getTableHeader()));
    The same Jtable have renderer where last column have Jcombobox componet.
    Here propbllem is that Jtable sorting is working properly but once i click renderer column header
    Jtable renderer is getting lost.
    Please tell me where i am doing mistake.
    Regards
    Qaisar

    Just a remark that nowadays, considering JTable has built-in support for row sorter, that enable you to specify sorting order, sorting algorithm (comparators), and to sort on demand, my first reaction is to warn that developping/using a specific model class for that is overkill (and probably inefficient, as the "sorting model" would likely fire spurious TableEvents although the gut contents have not changed (just been reordered).

  • High CPU issue due to table.setForeground() in JTable renderer

    Hi,
    I have a JTable with a renderer to set the text color for the row if certain conditions exist.
    The code below "works" although I have two issues:-
    1. The command "table.setForeground(Color.BLUE);" in the code below causes 50% CPU utilisation (Win XP, service pack 3). Very strange and consistent - tested on two different PCs.
    2. At times, the first column below the intended column changes color. The rest of the intended column has color set correctly.
    I'm using beans binding with the table concerned so can't post the table model - I believe the binding effectively has it's own model.
    Be greatful for any insight as it seems v. strange.....
    Thanks,
    </code>
            masterTable.setDefaultRenderer(String.class, textColour);
        TableCellRenderer textColour = new TableCellRenderer() {
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                MailingList mL = (MailingList) queryList.get((table.convertRowIndexToModel(row)));
                table.setForeground(Color.BLACK);
                if (mL.getApplicationAppId() != null) {
                    if (mL.getApplicationAppId().getSembookingsCollection() != null) {
                        Collection sB = mL.getApplicationAppId().getSembookingsCollection();
                        if (!sB.isEmpty()) {
    //                        table.setForeground(Color.BLUE);  //this line causes 50% CPU utilisation ???
                TableCellRenderer delegate = table.getDefaultRenderer(Object.class);
                return delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Here's my latest attempt, but still some questions and issues.
    I create a textColour class and this time attempt to set the colour on the component rather than the whole table in a similar fashion to the prepareRenderer(&hellip;) method.
    This appears to work and the CPU is no longer 50% utilisation.
    However, I still have the following questions/issues/observations:-
    1. I now need to set a renderer for each type of data. Perhaps this is the way it "should" be done. For example, I need to add " masterTable.setDefaultRenderer(Date.class, new textColour());" and then reformat the dates otherwise they don't change color. Would have been nice to set the colour for the whole row BUT can't see how as I can't use the preparedRenderer method?
    2. Perhaps related to the above, as I now return "comp", I don't call the default tableRenderer : i.e. " return delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);" {code} Is there a cleaner/"better" way to do this? If I do return the above, I don't see any colour change as my changed "comp" is replaced by returning the component from the default call above.
    3. Persumably I'm no longer in a loop as CPU is "normal" and no where near 50% (more like 0%). I still set the row to be BLACK first otherwise all rows change colour (BLUE) but looks like the row isn't rendered until the component is returned.
    4. I no longer have the second issue of colour being incorrect for the first column of one row. So that's good!
    Here's the latest ver of the code.......
    Thanks,
    {code:java}
            masterTable.setDefaultRenderer(String.class, new textColour());
            masterTable.setDefaultRenderer(Date.class, new textColour());
          public class textColour extends DefaultTableCellRenderer {
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                MailingList mL = (MailingList) queryList.get((table.convertRowIndexToModel(row)));
                Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if (value instanceof java.util.Date) {
                    this.setText(shortDf.format((Date) value));
                comp.setForeground(Color.BLACK);
                if (mL.getApplicationAppId() != null) {
                    if (mL.getApplicationAppId().getSembookingsCollection() != null) {
                        Collection sB = mL.getApplicationAppId().getSembookingsCollection();
                        if (!sB.isEmpty()) {
                            comp.setForeground(Color.BLUE);
    //            TableCellRenderer delegate = table.getDefaultRenderer(Object.class);
    //            return delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                return comp;
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Selecting text in a JTable renderer?

    Hi all,
    I have a JTable with some non-editable cells. I don't want the user to be able to change these values, but I want the user to be able to select the text and copy it. I can''t seem to be able to do this with the default cell renderers, as they subclass JLabel and you can't select text in the JLabel (or can you?)
    Anybody else have this problem?
    I also tried to create my own table renderer by subclassing a JTextField, but when I call setText in the "getTableCellRendererComponent" method, it doesn't seem to set the text of the text field. Well it does, because I can then call getText() and that works fine, but it doesn't appear in the JTable.
    any suggestions greatly appreciated,
    J

    Just in case anybody is interested, when you click on a table cell, the table cell editor is being used, not the cell editor.
    Its simply a matter of setting a textfield for that cell editor and setting setEditable to false.
    The user can then select the text, but not edit it. Works perfectly.
    J

  • JTable Renderer-Promblem when using custom renderer

    Hi. i've just started studying Swing component.
    So i'm about to ask for help to solve the problem during using custom TableCellRenderer.
    Here is my own Renderer which extends JLable and implements TableCellRenderer
    public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,boolean hasFocus,int row,int column)
         if (isSelected) {
         setForeground(table.getSelectionForeground());
         super.setBackground(table.getSelectionBackground());
         else {
         setForeground(table.getForeground());
         setBackground(table.getBackground());
         JLabel right=new JLabel("LEFT");
         JLabel left=new JLabel("RIGHT");
         this.setLayout(new BorderLayout());
         this.add(left,BorderLayout.WEST);
         this.add(right,BorderLayout.EAST);
         return this;
    note: There are 3 JLabel components. Two components are added to the component will be returned.
    This code works fine.
    but whenever try to resize the column display using above renderer, The " Text " runs in resizing.(making traces)
    Please anybody try to run this code, show me some solution.
    thank you

    A renderer will have its getTableCellRendererComponent method called repeatedly, every time a cell is to be repainted, and its the renderer associated with that cell. Therefore, avoid doing things in this method that should only be done once, for example:
    JLabel right=new JLabel("LEFT");
    JLabel left=new JLabel("RIGHT");
    this.setLayout(new BorderLayout());
    this.add(left,BorderLayout.WEST);
    this.add(right,BorderLayout.EAST);Can you do that in the renderer's constructor?

  • JTable Rendering

    Hi, Can anyone help in the following:
    I have implmented the JCheckBox Renderer in one of the fields of the table. It works fine but the problem is i cannot check multiple rows of data. When I check on row, the other one automatically unchecl.
    Here is my piece of code.
    package tv.izone.ide.table;
    public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer {
    public CheckBoxRenderer() {
    setOpaque(true);
    public Component getTableCellRendererComponent(JTable table, Object value,
              boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected) {
    setForeground(table.getSelectionForeground());
    setBackground(table.getSelectionBackground());
    } else{
    setForeground(table.getForeground());
    setBackground(UIManager.getColor("Button.background"));
    setSelected(isSelected);
    setText( (value ==null) ? "" : value.toString() );
    return this;
    And I am setting my Renderer like this
    table.getColumn("Copy").setCellRenderer(new CheckBoxRenderer());
    PLease Help.
    Thanks in adv.

    Ask Swing related questions in the Swing forum.
    You don't need to write your own renderer. Swing provides a check box renderer:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=419688

  • Problems with JTable Renderer

    I have a problem with applying a custom renderer. I know the renderer works so thats not the problem. If I do like this:
    DefaultTableModel aDefaultTableModel = new DefaultTableModel(data, columnNames);
    it works. But if I do like this:
    DefaultTableModel aDefaultTableModel;
    aDefaultTableModel.setDataVector(data, columNames);
    is doesn't, why?

    I think maybe it's not the renderer at all. It may be my custom TableModel thats causing problems. Now this doesn't work:
    private JTable aTable;
    private CustomTableModel aTableModel;
    public MyProgram() {
    aTableModel = new CustomTableModel();
    aTable = new JTable(aTableModel);
    aTableModel.setData(data, columnNames);
    private class CustomTableModel {
    private String[] columnNames = null;
    private Object[][] data = null;
    public CustomTableModel() {
    columnNames = new String[0];
    data = new Object[0][0];
    ... snip
    public void setData(Object[][] data, String[] columnNames) {
    this.data = data;
    this.columnNames = columnNames;
    fireTableDataChanged();
    ... snip
    Now, why doesn't that setData method work??

  • JTable: renderer problem-urgent

    Thanx "pasteven". That url is too good.
    I wrote my own renderer for each cell in JTable that uses JCombobox for rendering purpose. But when i select an item in that combo box, some times renderer is not setting the selected item in that combobox. Sometimes when i change the selection of item in the previous cell,it is getting reflected in all other cells of that particular column.
    Here is my code. Please help me.
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.table.TableCellEditor.*;
    import javax.swing.table.*;
    import javax.swing.DefaultCellEditor;
    public class Render extends javax.swing.JFrame {
    JTextField textField0=new JTextField();
    JComboBox cmb_Editor1=new JComboBox();
    JComboBox cmb_Editor2=new JComboBox();
    JComboBox cmb_Editor3=new JComboBox();
    EachRowRenderer rend;
    EachRowEditor eee;
    /** Creates new form Render */
    public Render() {
    initComponents ();
    rend=new EachRowRenderer();
    eee=new EachRowEditor(table);
    table.setDefaultRenderer(java.lang.Object.class,rend);
    table.setDefaultEditor(java.lang.Object.class,eee);
    cmb_Editor3.addItem("Y");
    cmb_Editor3.addItem("N");
    eee.setEditorAt(0,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(1,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(2,1,new DefaultCellEditor(cmb_Editor3));
    eee.setEditorAt(0,2,new DefaultCellEditor(new JCheckBox()));
    rend.add(0,2,new CheckBoxCellRenderer());
    rend.add(0,1,new ComboBoxCellRenderer(cmb_Editor3));
    rend.add(1,1,new ComboBoxCellRenderer(cmb_Editor3));
    rend.add(2,1,new ComboBoxCellRenderer(cmb_Editor3));
    JCheckBox chk=new JCheckBox();
    pack ();
    public class EachRowEditor implements TableCellEditor {
    protected Hashtable editors;
    protected TableCellEditor editor, defaultEditor;
    JTable table;
    public EachRowEditor(JTable table) {
    this.table = table;
    editors = new Hashtable();
    defaultEditor = new DefaultCellEditor(new JTextField());
    public void setEditorAt(int row,int column, TableCellEditor editor) {
    editors.put(""+row+column,editor);
    public Component getTableCellEditorComponent(JTable table,
    Object value, boolean isSelected, int row, int column) {
    return editor.getTableCellEditorComponent(table,
    value, isSelected, row, column);
    public Object getCellEditorValue() {
    return editor.getCellEditorValue();
    public boolean stopCellEditing() {
    return editor.stopCellEditing();
    public void cancelCellEditing() {
    editor.cancelCellEditing();
    public boolean isCellEditable(EventObject anEvent) {
    selectEditor((MouseEvent)anEvent);
    // editor.isCellEditable(anEvent);
         return true;
    public void addSeperateCellEditorListener(int row,int column,CellEditorListener l) {
    editor=(TableCellEditor)editors.get(""+row+column);
    editor.addCellEditorListener(l);
    public void addCellEditorListener(CellEditorListener l) {
    editor.addCellEditorListener(l);
    public void removeCellEditorListener(CellEditorListener l) {
    editor.removeCellEditorListener(l);
    public boolean shouldSelectCell(EventObject anEvent) {
    selectEditor((MouseEvent)anEvent);
    return editor.shouldSelectCell(anEvent);
    protected void selectEditor(MouseEvent e) {
    int row;
    int column;
    if (e == null) {
    row = table.getSelectionModel().getAnchorSelectionIndex();
    column=table.getSelectionModel().getLeadSelectionIndex();
    } else {
    row = table.rowAtPoint(e.getPoint());
    column=table.columnAtPoint(e.getPoint());
    editor = (TableCellEditor)editors.get(""+row+column);
    if (editor == null) {
    editor = defaultEditor;
    public class CheckBoxCellRenderer extends JCheckBox implements TableCellRenderer
    CheckBoxCellRenderer() {
    setHorizontalAlignment(JLabel.CENTER);
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setSelected((value != null && ((Boolean)value).booleanValue()));
    setToolTipText("checkbox");
    return this;
    public class TextFieldCellRenderer extends JTextField implements TableCellRenderer
    JTextField textField;
    TextFieldCellRenderer(JTextField textField) {
    this.textField=textField;
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setText((textField.getText() != null) ? textField.getText() : "");
    return textField;
    public class ComboBoxCellRenderer extends JComboBox implements TableCellRenderer
    JComboBox comboBox=null;
    ComboBoxCellRenderer(JComboBox comboBox) {
    this.comboBox=comboBox;
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setSelectedItem(comboBox.getSelectedItem());
    return this;
    public class EachRowRenderer implements TableCellRenderer {
    protected Hashtable renderers;
    protected TableCellRenderer renderer, defaultRenderer;
    public EachRowRenderer() {
    renderers = new Hashtable();
    defaultRenderer = new DefaultTableCellRenderer();
    public void add(int row,int column ,TableCellRenderer renderer) {
    renderers.put(""+row+column,renderer);
    public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus,
    int row, int column) {
    renderer = (TableCellRenderer)renderers.get(""+row+column);
    if (renderer == null) {
    renderer = defaultRenderer;
    return renderer.getTableCellRendererComponent(table,
    value, isSelected, hasFocus, row, column);
    /** 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 FormEditor.
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    table = new javax.swing.JTable();
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    table.setModel(new javax.swing.table.DefaultTableModel (
    new Object [][] {
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null},
    {null, null, null, null}
    new String [] {
    "Title 1", "Title 2", "Title 3", "Title 4"
    Class[] types = new Class [] {
    java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
    public Class getColumnClass (int columnIndex) {
    return types [columnIndex];
    jScrollPane1.setViewportView(table);
    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit (0);
    * @param args the command line arguments
    public static void main (String args[]) {
    new Render ().show ();
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable table;
    // End of variables declaration
    Please help me.

    I ran into the same problem in Java 1.4. The problem is that the JTable is not feeding the initial value to the cell editor. I found the following workaround. You have to override the JTable method prepareEditor() like this:
    <CODE>
    public Component prepareEditor(TableCellEditor editor, int row, int column) {
    Component ret = super.prepareEditor(editor, row, column);
    // Translate column to the data model coordinates by using the
    // identifier. We'll check only for the JComboBox columns (in
    // this example columns 8 and 9).
    int col = 0;
    String id = (String)getColumnModel().getColumn(column).getIdentifier();
    if ( id.equals( tableModel.getColumnName(8) ) )
    col = 8;
    else if ( id.equals( tableModel.getColumnName(9) ) )
    col = 9;
    if (col == 8 || col == 9) {
    String item = (String)tableModel.getValueAt(row, col);
    ((JComboBox)((DefaultCellEditor)editor).getComponent()).setSelectedItem( item );
    return ret;
    </CODE>
    You have to translate from table coordinates to table model coordinates in case the user reorders column - if you don't allow this for your table then you won't have to do this.

  • JTable rendering problem in JRE 1.6.0.10 under Linux

    I've encountered a bizarre issue using JTable. I've got a 3x10 JTable of Strings, values in which I change from within the program (no user input). After every update the value in the first column gets superimposed on the top of the previous one, so they are both visible, but totally unreadable (they interlace).
    I'm using Linux, and it only happens under jre 1.6.0.10. When I switch to 1.5.0.16 it works fine. I also noticed, that if I set the value to null in the first column and then set it to the new value it works fine. However, if I do it simply like that:
    table.setValueAt(null, 1, 0);
    table.setValueAt(newValue, 1, 0);it doesn't work. I need to re-set it to null on one user's click (it triggers the update) and only change it on the following click. Am I reporting a bug here, or is it a known issue with some proper solution?
    Thanks

    There are some crazy things, I can't explain...
    1) Here is my [sample project|http://vlkv.storm-soft.kiev.ua/_mywiki/images/6/6f/JavaApplication1.tar.gz]. I've created it with NetBeans 6.5 and jdk 1.6.0_11.
    2) there are directories dist_windows, dist_linux with jars, created under Windows and Linux (same version JDK everywhere). You may compare both JavaApplication1.jar files with some diff tool (such as WinMerge) and you can see that these jars are slightly different. WHY?
    3) Run my sample
    java -jar JavaApplication1.jarpress the button and scroll up and down JTable. Under Windows everything is ok. But under Linux I have the subj bug with BOTH dist_windows/JavaApplication1.jar and dist_linux/JavaApplication1.jar !!!
    4) Start NetBeans 6.5 and open the project. Run the project from inside NetBeans on Linux. Then I see that my java program runs perfectly, without any bugs!!!
    This command
    ps fu -C javaproduces this output:
    vlkv 8778 1.0 2.8 217084 22408 ? Sl 14:01 0:00 \_ /usr/java/jdk1.6.0_11/bin/java -classpath /home/vlkv/NetBeansProjects/JavaApplication1/build/classes:/home/vlkv/NetBeansProjects/JavaApplication1/src NewJFrame
    But if I run NewJFrame without NetBeans like this (copy/paste command):
    /usr/java/jdk1.6.0_11/bin/java -classpath /home/vlkv/NetBeansProjects/JavaApplication1/build/classes:/home/vlkv/NetBeansProjects/JavaApplication1/src NewJFrame
    This bug returns!!! WHY UNDER NETBEANS IT'S OKAY?
    Where are the java experts to help us, please?
    PS: I've found a topic about this problem, unfortunately not answered, here .

  • Problem in JTable Renderer and Editor

    Hi All
    I have created a JTable with one Column have the Custom TableCellRender, and TableCellEditor
    Which has the a JPanel with one lable and a button.
    Problem is:
    I have to edit the content of table by clicking the button, i will select some data from another dialog,
    if i select that data the cell contenet is not updating, and i can not able to select any other cell in the table.
    if i resize the colomn the above problem will solve.
    Please help on this to fix

    Hello,
    Very sorry but it is difficult to understand your problem.
    Anyway you should have a careful look on Sun's Tutorial for JTable:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Be patient as JTable are complex components.
    Good luck, Frank

  • Custom JTable rendering in Matisse?

    I am new to Swing development and need to show some tabular data in a jtable and a value in one of the colums determines the backgound colur for that row. I have done some investigation and it appears that you can subclass JTable and override the prepareRenderer() method to achieve this. How do you do this in the Netbeans Matisse editor, when I try to do this the IDE wont let me overwrite code that the IDE maintains.
    Any help greatly appreciated.
    Thanks
    C

    From NetBeans Help:
    To modify a form component's guarded block:
    In the Inspector window, select the component whose initialization code you want to edit.
    Click the Code button at the top of the Properties window to view the Code properties.
    Select the property you wish to edit and enter the desired value.
    The IDE updates the selected component's guarded code block with the new value.
    (Help | Java Applications | Building Java GUIs | Designing Java GUIs | Modifying GUI Source Code)

  • JTable Renderer

    I am trying to develop an application that allows users to enter in scores into a table.
    How can I access a particular row/cell in a table and add it to another row/cell. Is it possible to add a JTextfield to a Row/Cell???
    Hope you can understand what I�m asking; any code example would be very helpful. Thanks

    Here is an example that adds 2 columns and displays the result in a third column:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566133

  • Beans Binding with JTable Problem

    Does anyone have an idea on how to make the columns of a JTable (with binded elements) not editable? I'm currently using the binding feature of NetBeans 6.0 M9.

    Override the tables isCellEditable method to always return false.

  • Refresh jTable after inserting new data into the Database

    Hey all,
    I'm using Netbeans 6.5 to create a Desktop Application which is connected to a Java DB (Derby).
    The first simple steps were all very successfull:
    Create the jTable and bind it to the Database => everything works fine. When the application starts it correctly shows all data from the database.
    The problem starts when I try to insert new data to the database.
    For that reason I've created textfields and a button "Save". When I press the button it successfully inserts the data to the database but they are not displayed in the jTable (when the application starts they are all there, they are not updated at runtime) . I've tried table.invalidate() and table.repaint() but they just don't work.
    Any help will be GREATLY appreciated. But please have in mind that most of the code is Netbeans-generated and most of it not editable.
    Many thanks in advance.
    George

    Once again you are right my friend. I jumped to conclusion way too fast, when I shouldn't. (Give me a break, I've been busting my head with this well over a week). The response I saw when I did that was that indeed a line is added to the jTable. Because I falsly set the index of the object to be added to be second to last the row appeared on the table, what I didn't see at the time was that the last one disappeared. Hmm...
    A new adventure begins...
    So after a few hours of messing around with it here are my observations:
    1) It was not an observable list. When I add the new element with employeesList.add(newEmp); , the table gets notified but a get a bunch of exceptions:
    xception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 84, Size: 84
            at java.util.ArrayList.RangeCheck(ArrayList.java:546)
            at java.util.ArrayList.get(ArrayList.java:321)
            at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
            at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
            at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)
            at javax.swing.JTable.getValueAt(JTable.java:1903)
            at javax.swing.JTable.prepareRenderer(JTable.java:3911)
            at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
            at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
            at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1897)
            at javax.swing.plaf.ComponentUI.update(ComponentUI.java:154)
            at javax.swing.JComponent.paintComponent(JComponent.java:743)
            at javax.swing.JComponent.paint(JComponent.java:1006)
            at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1602)
            at javax.swing.JViewport.windowBlitPaint(JViewport.java:1568)
            at javax.swing.JViewport.setViewPosition(JViewport.java:1098)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPaneUI.java:818)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI.java:807)
            at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:348)
            at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:285)
            at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151)
            at javax.swing.JScrollBar.setValue(JScrollBar.java:441)
            at javax.swing.plaf.basic.BasicScrollBarUI.scrollByUnits(BasicScrollBarUI.java:907)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.mouseWheelMoved(BasicScrollPaneUI.java:778)
            at javax.swing.plaf.basic.BasicScrollPaneUI$MouseWheelHandler.mouseWheelMoved(BasicScrollPaneUI.java:449)
            at apple.laf.CUIAquaScrollPane$XYMouseWheelHandler.mouseWheelMoved(CUIAquaScrollPane.java:38)
            at java.awt.Component.processMouseWheelEvent(Component.java:5690)
            at java.awt.Component.processEvent(Component.java:5374)
            at java.awt.Container.processEvent(Container.java:2010)
            at java.awt.Component.dispatchEventImpl(Component.java:4068)
            at java.awt.Container.dispatchEventImpl(Container.java:2068)
            at java.awt.Component.dispatchMouseWheelToAncestor(Component.java:4211)
            at java.awt.Component.dispatchEventImpl(Component.java:3955)
            at java.awt.Container.dispatchEventImpl(Container.java:2068)
            at java.awt.Component.dispatchEvent(Component.java:3903)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
            at java.awt.Container.dispatchEventImpl(Container.java:2054)
            at java.awt.Window.dispatchEventImpl(Window.java:1801)
            at java.awt.Component.dispatchEvent(Component.java:3903)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 84, Size: 84
            at java.util.ArrayList.RangeCheck(ArrayList.java:546)
            at java.util.ArrayList.get(ArrayList.java:321)
            at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
            at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
            at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)
            at javax.swing.JTable.getValueAt(JTable.java:1903)
            at javax.swing.JTable.prepareRenderer(JTable.java:3911)
            at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
    ... and a lot morewhich from my poor understanding means that the jTable succesfully notices the change but it is not able (??) to adjust to the new change. What is more interesting is that when I plainly add the element to the end of the list (without an idex that is), a blank row appears at the end of my Table. The weird thing is that I've bound the table to some text fields below it, and when I select that empty row all the data appear correctly to the text fields.
    I tried going through:
                    org.jdesktop.observablecollections.ObservableCollections.observableList(employeesList).add(newEmp);as well as
                    help = org.jdesktop.observablecollections.ObservableCollections.observableListHelper(employeesList);
                    help.getObservableList().add(newEmp);
                    help.fireElementChanged(employeesList.lastIndexOf(newEmp));and
                    obsemployeesList = org.jdesktop.observablecollections.ObservableCollections.observableList(employeesList);
                    obsemployeesList.add(newEmp);and I still get the same results (both the exeptions and the mysterious empty row at the end of the table
    So, I'm again in terrible need of your advice. I can't thank you enough for the effort you put into this.
    Best regards,
    George
    Edited by: tougeo on May 30, 2009 11:06 AM
    Edited by: tougeo on May 30, 2009 11:21 AM
    Edited by: tougeo on May 30, 2009 11:30 AM

Maybe you are looking for

  • Open file in a folder

    if i have a powerpoint file myfile.pps and i saved in a folder of any folder name in the f:// directory, how do i execute the file? Using this following codeRuntime.getRuntime().exec(new String[] {"cmd /c start", "f:/myfile.pps"});thanks

  • How do you add a hyperlink to an image in Captivate 6?

    I have a slide that contains two images. I want the user to be able to click on each image and have the URL open in a new window. I can't figure out how to do this simple procedure. Thank you!

  • HT201320 Setup a 2nd e mail account

    Trying to setup AOL e mail and settings opens then closes also can't open contacts

  • Can anybody help me to display double zero or leading zero in a pence column?

    I am trying to convert a public service form which uses sep. columns for pounds and pence - I understand that this is madness but I have to use this for now. I need pence to show as 00 or 06 or 12. In MS Excel it is straightforward but Numbers seems

  • XMLAgg() length limitations of the content?

    Hi all, Is there a limitation of the content of the XMLAgg() function? When I do the following query, I've got a result: SELECT XMLAGG(XMLElement("Company", XMLAttributes(fc.id as "I", fc.short_name as "SN"), fc.name)) as result FROM fas_companies fc