Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

propertyChangeEvent problem with JTable in 1.3 and higher

Status
Not open for further replies.

dddutcher

Programmer
Oct 3, 2001
5
US
Using the Java plug-in 1.3 or higher, this code does not work. 1.2 works fine.

The propertyChangeEvent is never fired by the JTable. Any suggestions on what I could be doing wrong? Any help is greatly appreciated.

Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import java.lang.Exception;
import javax.swing.JOptionPane;
import javax.swing.table.*;
import javax.swing.event.*;

public class JTableTest extends JApplet {
    boolean isStandalone = false;

    public String getParameter(String key, String def) {
        if (isStandalone) {
            return System.getProperty(key, def);
        }
        if (getParameter(key) != null) {
            return getParameter(key);
        }
        return def;
    }

    public JTableTest() {
    }

    public void init() {
        //getContentPane().add(testPanel);
        TimeSheetGrid grid = new TimeSheetGrid();
        getContentPane().add(grid);

    }

    public String getAppletInfo() {
        return "Applet Information";
    }

    public String[][] getParameterInfo() {
        return null;
    }

    static {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}






import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

public class TimeSheetGrid extends JPanel
                           implements TableColumnModelListener

{

    private AVGridTableColumnModel  cmMain  = null;
    private JTable JTableMain   = new JTable(2, 5);
    private JScrollPane JScrollMain  = new JScrollPane(JTableMain);

    public TimeSheetGrid()
    {
        super();
	init();
    }

    private void init()
    {
	setLayout(new BorderLayout(0,0));
	JScrollMain.setPreferredSize(new Dimension(600, 460));		 
        JScrollMain.setHorizontalScrollBarPolicy
(JScrollMain.HORIZONTAL_SCROLLBAR_NEVER);
        JScrollMain.setVerticalScrollBarPolicy
(JScrollMain.VERTICAL_SCROLLBAR_ALWAYS);
	add(JScrollMain, BorderLayout.CENTER);

        cmMain = new AVGridTableColumnModel();
	cmMain.addColumnModelListener( this );
	JTableMain.setColumnModel( cmMain );
	JTableMain.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	JTableMain.setColumnSelectionAllowed(false);
	JTableMain.getTableHeader().setReorderingAllowed( true );
	JTableMain.getColumnModel().addColumnModelListener( this );
    }

    public void columnAdded(TableColumnModelEvent e){}

    public void columnRemoved(TableColumnModelEvent e) {}

    public void columnMoved(TableColumnModelEvent e) {}

    public void columnMarginChanged(ChangeEvent e)
    {
        System.out.println("Column Margin Changed");
    }

    public void columnSelectionChanged(ListSelectionEvent e){}
}




import java.beans.PropertyChangeEvent;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;

public class AVGridTableColumnModel extends DefaultTableColumnModel
{

    private TableColumn col = null;

    AVGridTableColumnModel()
    {
        super();
        init();
    }

    public void init()
    {
        for (int i = 0; i < 5; i++)
        {
            col = new TableColumn();
            col.setHeaderValue(&quot;colHdr&quot;+ i);
            col.addPropertyChangeListener( this );
            addColumn(col);
        }
    }

    public void propertyChange(PropertyChangeEvent evt)
    {
        String name = evt.getPropertyName();
        System.out.println(name);
	if (name.equals(&quot;columWidth&quot;)) {

            System.out.println(&quot;Property Change Event fired&quot;);
	    super.fireColumnMarginChanged();
	}
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top