This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 162496 - "columnModel" property of JTable not always remembered
Summary: "columnModel" property of JTable not always remembered
Status: RESOLVED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.0
Hardware: All All
: P3 blocker with 3 votes (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-13 10:11 UTC by danie
Modified: 2011-07-27 13:52 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description danie 2009-04-13 10:11:39 UTC
The "columnModel" property of JTables are only partially persisted. The property still remains in bold text (indicating
that a custom value has been set), but upon viewing the value, the default value displays. Executing in this state
results in a table with no column model (or at least empty column model).

Steps to reproduce:

1. Create a JFrame in die GUI editor.
2. Add a table to it.
3. Set autoCreateColumnsFromModel to false.
4. Create a custom column model (i.e. set the value to createColumnModel() and return a model from this method).
5. Execute and it should work just fine.
6. Do some of the following in arbitrary sequence: close the GUI editor, reload it, edit some other property/component
in the JFrame. (I haven't been able to determine exactly what makes the property get lost, but it happens daily!)
7. Now upon execution, the table will not show any columns. And upon inspection the property will still appear bold, but
with the default value, not the custom column model.

I've noticed no exceptions in Netbeans that could "cause" this, but it does prevent one from opening "Customize code"
until the property is set to the custom value "createColumnModel()" again.
Comment 1 Jan Stola 2009-04-14 14:55:16 UTC
I am sorry, I am not able to reproduce this issue. Please, let me know if/when you find _exact_ steps to reproduce. 
Thank you in advance.
Comment 2 danie 2009-04-30 12:47:22 UTC
Exact steps to reproduce:

1. Create JFrame in form editor, call it for instance ReproduceBug.java
2. Add JTable to it
3. set autoCreateColumnsFromModel to false
4. Provide a custom column model (see code below)
5. Run ReproduceBug.java, it should display the table in the frame
6. Close the ReproduceBug.java file
7. Open the ReproduceBug.java file again
8. Change for instance the rowHeight to 17
9. Run ReproduceBug.java, the frame and table is displayed, but now columns
10. On closer inspection, the columnModel property is not set anymore, and clicking on customize code, results in an
exception (see below).

I can reproduce this always on:
Windows Vista Business 32bit
JDK 6u13
Netbeans 6.5.1

CODE TO REPRODUCE:


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ReproduceBug.java
 *
 * Created on Apr 30, 2009, 1:13:04 PM
 */

package jspray.gui;

import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author Danie
 */
public class ReproduceBug extends javax.swing.JFrame {

    /** Creates new form ReproduceBug */
    public ReproduceBug() {
        initComponents();
    }

    /** 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 Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        table.setAutoCreateColumnsFromModel(false);
        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"
            }
        ));
        jScrollPane1.setViewportView(table);
        table.setColumnModel(createColumnModel());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ReproduceBug().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable table;
    // End of variables declaration

    private TableColumnModel createColumnModel() {
        TableColumnModel colMod = new DefaultTableColumnModel();

        for (int count = table.getModel().getColumnCount(), i = 0; i < count; i++) {
            TableColumn c = new TableColumn(i);
            c.setHeaderValue(table.getModel().getColumnName(i));

            colMod.addColumn(c);
        }

        return colMod;
    }
}

FORM FILE:
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
  <Properties>
    <Property name="defaultCloseOperation" type="int" value="3"/>
  </Properties>
  <SyntheticProperties>
    <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
  </SyntheticProperties>
  <AuxValues>
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
  </AuxValues>

  <Layout>
    <DimensionLayout dim="0">
      <Group type="103" groupAlignment="0" attributes="0">
          <Group type="102" alignment="0" attributes="0">
              <EmptySpace max="-2" attributes="0"/>
              <Component id="jScrollPane1" pref="380" max="32767" attributes="0"/>
              <EmptySpace max="-2" attributes="0"/>
          </Group>
      </Group>
    </DimensionLayout>
    <DimensionLayout dim="1">
      <Group type="103" groupAlignment="0" attributes="0">
          <Group type="102" alignment="0" attributes="0">
              <EmptySpace max="-2" attributes="0"/>
              <Component id="jScrollPane1" pref="278" max="32767" attributes="0"/>
              <EmptySpace max="-2" attributes="0"/>
          </Group>
      </Group>
    </DimensionLayout>
  </Layout>
  <SubComponents>
    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
      <AuxValues>
        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
      </AuxValues>

      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
      <SubComponents>
        <Component class="javax.swing.JTable" name="table">
          <Properties>
            <Property name="autoCreateColumnsFromModel" type="boolean" value="false"/>
            <Property name="model" type="javax.swing.table.TableModel"
editor="org.netbeans.modules.form.editors2.TableModelEditor">
              <Table columnCount="4" rowCount="4">
                <Column editable="true" title="Title 1" type="java.lang.Object"/>
                <Column editable="true" title="Title 2" type="java.lang.Object"/>
                <Column editable="true" title="Title 3" type="java.lang.Object"/>
                <Column editable="true" title="Title 4" type="java.lang.Object"/>
              </Table>
            </Property>
            <Property name="columnModel" type="javax.swing.table.TableColumnModel"
editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
              <Connection code="createColumnModel()" type="code"/>
            </Property>
          </Properties>
        </Component>
      </SubComponents>
    </Container>
  </SubComponents>
</Form>

EXCEPTION WHEN CLICKING "Customize Code" ON JTable AFTER FAILURE:

java.lang.NullPointerException
	at org.netbeans.modules.form.CustomCodeView.addGuardedCode(CustomCodeView.java:326)
	at org.netbeans.modules.form.CustomCodeView.buildCodeView(CustomCodeView.java:244)
	at org.netbeans.modules.form.CustomCodeView.setCodeData(CustomCodeView.java:183)
	at org.netbeans.modules.form.CodeCustomizer.selectComponent(CodeCustomizer.java:127)
	at org.netbeans.modules.form.CodeCustomizer.show(CodeCustomizer.java:87)
	at org.netbeans.modules.form.actions.CustomCodeAction.performAction(CustomCodeAction.java:55)
	at org.openide.util.actions.NodeAction$DelegateAction$1.run(NodeAction.java:581)
	at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:77)
	at org.openide.util.actions.NodeAction$DelegateAction.actionPerformed(NodeAction.java:577)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1225)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1266)
	at java.awt.Component.processMouseEvent(Component.java:6216)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
	at java.awt.Component.processEvent(Component.java:5981)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4583)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4413)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Window.dispatchEventImpl(Window.java:2475)
	at java.awt.Component.dispatchEvent(Component.java:4413)
[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

This exception is logged elsewhere as Exception 197043.

I believe this bug is one of the several causes of Issue 154829.
Comment 3 Jan Stola 2009-10-04 17:27:04 UTC
Thank you for the exact steps to reproduce. I am able to reproduce the issue now.

Simple steps to reproduce:
1. Create JFrame.
2. Insert JTable into JFrame.
3. Set columnModel property using 'User Code' property editor.
4. Save the JFrame.
5. Close/reopen or reload the form.
6. Modify the JFrame somehow to force code regeneration
   => jTable1.setColumnModel(null); statement is lost from the source code
   => the mentioned exception is thrown when Customize Code action is invoked over JTable
Comment 4 _ rsmogura 2010-10-10 15:23:28 UTC
Same here. I got this bug on 6.9 and 6.10M1.
Comment 5 ldlopez 2011-07-24 15:01:23 UTC
Same here. I got this bug on 7.0
Comment 6 Jan Stola 2011-07-27 13:48:45 UTC
I have found the root of the problem. 'columnModel' property of JTable is marked as 'parent dependent', i.e., is handled somehow special by the GUI builder. Unfortunately, it turned out that this special handling is not correct with respect to the setting of the current property editor.
Comment 7 Jan Stola 2011-07-27 13:52:57 UTC
Fixed.

Modified file: http://hg.netbeans.org/jet-main/rev/60200c6ed50e