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

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).

  • 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?

  • 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.

  • 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}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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 .

  • 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.

  • 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

  • JTable (yes, again) with TableSorter - exception in the second request.

    While using the TableSorter the data is populated correctly and I manage to sort the items (beautiful)
    say I ask for a list of items and the return result is 20 and the second time I'll ask for a list of items where the return result is greater than 20 items an error will occur with reference to: java.lang.ArrayIndexOutOfBoundsException : 10
    com.softme.jtable.Renderer.TableSorter.modelIndex(TableSorter.java:207)
    com.softme.jtable.Renderer.TableSorter.getValueAt(TableSorter.java:249)
        public int modelIndex(int viewIndex)
             return getViewToModel()[viewIndex].modelIndex;         
        }any idea why this happens?

    I am also getting this same Exception... I have tried various things to prevent this from happening. I can state that in my case I am running table model updates in a SwingWorker Thread to create a visual effect on the screen (rows are being processed and updated as the user watches)
    Could this be a problem of the JTable object accessing the getValue method to update the screen at the same time as the Thread is accessing it for the test value locking the model index object?
    Just a thought.
    This problem is very annoying to the user as it only happens once-in-a-while. Thanks for any help on this problem.
    Here is the changes I made to the code and the error I get... As you can see I test for NULL before running the line, it passes and then STILL gives a NullPointerExcpetion... this is why I am thinking Thread issue...
    public int modelIndex(int viewIndex) {
             Row[] row = getViewToModel();
             if (row == null) System.out.println("?: " +viewIndex);
             if (row != null) {
                  return row[viewIndex].getModelIndex(); //this line is throwing the NPE
             else
                  return -1;
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at com.adriansteel.rpg.rpgSubfileSorter.modelIndex(rpgSubfileSorter.java:323)
         at com.adriansteel.rpg.rpgSubfileSorter.getValueAt(rpgSubfileSorter.java:363)
         at javax.swing.JTable.getValueAt(Unknown Source)
         at javax.swing.JTable.prepareRenderer(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
         at javax.swing.plaf.ComponentUI.update(Unknown Source)
         at javax.swing.JComponent.paintComponent(Unknown Source)
         at javax.swing.JComponent.paint(Unknown Source)
         at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
         at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
         at javax.swing.JComponent._paintImmediately(Unknown Source)
         at javax.swing.JComponent.paintImmediately(Unknown Source)
         at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

  • JSpinner inside JTable

    I implemented a JTable where a Column is of 'type' JSpinner. I have a class
    SpinnerRenderer implements TableCellRenderer to implement JSpinner rendering in the cell
    and a class
    SpinnerCellEditor extends       AbstractCellEditor
                                   implements   TableCellEditor to return a JSpinner to edit.
    Note: both classes return proper JSpinner located in a global Vector
    without creating a new one each time.
    My problem is where to place the fireEditingStopped method of SpinnerCellEditor as some JSpinner remains
    active, no more linked to the JTable rendering and repainted without rigth context.
    Any suggestion would be really welcome.
    Thanks
    jjmoka

    Try these:
    http://www.mail-archive.com/[email protected]/msg01181.html
    http://javaalmanac.com/egs/javax.swing.table/Spinner.html?l=rel
    and/or, Google for "jspinner jtable"
    Jamie

Maybe you are looking for

  • How to create lead follow up opportunity....

    Hello, How to create lead follow up opportunity automatically... Also my clients need is when we change the status of Lead from Open or In-Process or Won to Completed then an automatic email should go to the employee responsible in the lead. Please h

  • How to trun off batch determination for certain shipping points ?

    During Delivery Notes creation we would like to turn off the batch determination on basis of certail shipping points. can some please guide what is the best way to do it. We do not want it turned off for all the shipping points but for a special ones

  • When I press shutdown nothing happen in KDE

    after long time I update my arch linux with pacman and many packages like KDE update to new version , but after upgrade packages and reboot system by command I see error about udev and HAL ,when system boot , and when I choose shutdown option in KDE

  • Broken Link Report with Variables

    In my broken links report, I have many links that contain dynamic variables that will be realized at execution time and are not static links. I have included some code from our page(s) below. This process works extremely well for our web pages, but I

  • Incompatible type  -  use of String datatype?

    I tried to compile the program but it seems to show "synax errors". What I complied the program below: import java.util.Scanner; public class String    public static void main(String[] args)       // declare constants and variables       String tutor