Re: Adjusting column widths of PropertySheetView

[email protected]
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <[email protected]>
Thanks everyone for the pointers. Here is what I did which seems to
work fine during layout and re-sizing. This is a bit of a hack as what
I really would have liked is for the Property Sheet to try to resize
its own columns to best fit the displayed data. For my purposes and my
data I settled on a hard-coded width of 100 pixels for the Property
Names.

If anyone wants to do something similar, here's what I did:

In the constructor for the Property Sheet (via Custom Code Creation in
the GUI designer of NetBeans), put this:

new PropertySheetView(){
    @Override 
    public void doLayout()
    {
     super.doLayout();
     setPropertyTableColumnWidths();
    }
}

Then in the body of class that includes the Property Sheet (a
MultiViewElement in my case), include the following two functions:

 void setPropertyTableColumnWidths()
    {
	findJTableinComponent(propertySheetView1);
    }
    
    boolean findJTableinComponent(JComponent comp)
    {
      Component[] Components = comp.getComponents(); 
      if ((Components==null)||(Components.length==0)) return false;
      for (Component incomp: Components)
	{
//	     log.info("Reviewing Property Views components: "+incomp);
	   if (incomp instanceof JTable)
	    {
	       
((JTable)incomp).getColumnModel().getColumn(0).setMaxWidth(100);
	       
((JTable)incomp).getColumnModel().getColumn(0).setPreferredWidth(100);
	       
((JTable)incomp).getColumnModel().getColumn(0).setResizable(false);
//		  log.info("Adjusted Property Views preferred column
width for column 0");
		return true;  
	    } 
	   if (incomp instanceof JComponent)
	   {
//		 log.info("Checking Children... "+incomp);
	       if (findJTableinComponent((JComponent) incomp)) return
true;
	   }
	}
      return false;
    }

It seems that the doLayout() function is called at least a couple of
times before the UI is fully initialized, so it is OK that the column
widths are set after the call to super.doLayout(). The
findJTableinComponent function is recursively looking for a SheetTable,
which is based on a JTable. 

Suggestions always welcome

Steve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.