JIDE 3.5.15

com.jidesoft.grid
Class AutoResizePopupMenuCustomizer

java.lang.Object
  extended by com.jidesoft.grid.AutoResizePopupMenuCustomizer
All Implemented Interfaces:
TableHeaderPopupMenuCustomizer

public class AutoResizePopupMenuCustomizer
extends Object
implements TableHeaderPopupMenuCustomizer

A TableHeaderPopupMenuCustomizer to auto resize a column or all columns. To use it, you can use the code like this.

 TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(aggregateTable)
 installer.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer());
 


Field Summary
static String CONTEXT_MENU_AUTO_RESIZE
          CONTEXT_MENU_...
static String CONTEXT_MENU_AUTO_RESIZE_ALL
           
 
Constructor Summary
AutoResizePopupMenuCustomizer()
           
 
Method Summary
 void customizePopupMenu(JTableHeader header, JPopupMenu popup, int clickingColumn)
          The method generates the context menu items by clickingColumn.
protected  String getColumnName(JTableHeader header, int clickingColumn)
          Gets the column name of the clicking column.
 int[] getMinimumWidth()
          Gets the minimum width of the columns.
protected  String getResourceString(String key)
          Gets the localized string from resource bundle.
 boolean isConsiderTableHeader()
          Checks if we consider the table header when resizing.
 boolean isConsiderVisibleRowsOnly()
          Checks if we only consider the visible rows when resizing.
 void setConsiderTableHeader(boolean considerTableHeader)
          Sets the flag whether the table header is considered when resizing.
 void setConsiderVisibleRowsOnly(boolean considerVisibleRowsOnly)
          Sets the flag whether it should resize based on the visible rows only.
 void setMinimumWidth(int[] minimumWidth)
          Sets the minimum width of each column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_MENU_AUTO_RESIZE

public static final String CONTEXT_MENU_AUTO_RESIZE
CONTEXT_MENU_... are the possible menu names displayed in the menu. You can use these string as name to locate the existing menu items.

See Also:
customizePopupMenu(javax.swing.table.JTableHeader, javax.swing.JPopupMenu, int), Constant Field Values

CONTEXT_MENU_AUTO_RESIZE_ALL

public static final String CONTEXT_MENU_AUTO_RESIZE_ALL
See Also:
Constant Field Values
Constructor Detail

AutoResizePopupMenuCustomizer

public AutoResizePopupMenuCustomizer()
Method Detail

isConsiderVisibleRowsOnly

public boolean isConsiderVisibleRowsOnly()
Checks if we only consider the visible rows when resizing.

Returns:
true or false.

setConsiderVisibleRowsOnly

public void setConsiderVisibleRowsOnly(boolean considerVisibleRowsOnly)
Sets the flag whether it should resize based on the visible rows only. This is to mimic the auto-resize behave in Vista Explorer. It is helpful for the performance when there are a huge number of rows in the table.

Parameters:
considerVisibleRowsOnly - true if you want to the auto-resize to consider the visible rows only. False to not consider.

isConsiderTableHeader

public boolean isConsiderTableHeader()
Checks if we consider the table header when resizing.

Returns:
true or false.

setConsiderTableHeader

public void setConsiderTableHeader(boolean considerTableHeader)
Sets the flag whether the table header is considered when resizing.

Parameters:
considerTableHeader - true if you want to the auto-resize to consider the table header preferred width. False to not consider.

getMinimumWidth

public int[] getMinimumWidth()
Gets the minimum width of the columns.

Returns:
the minimum width.

setMinimumWidth

public void setMinimumWidth(int[] minimumWidth)
Sets the minimum width of each column. This is used when auto resizing the columns so that it will never go below the specified minimum width.

Parameters:
minimumWidth - the new minimum width.

getResourceString

protected String getResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in grid.properties that begin with "TableColumnChooser.".

Parameters:
key - the resource string key
Returns:
the localized string.

customizePopupMenu

public void customizePopupMenu(JTableHeader header,
                               JPopupMenu popup,
                               int clickingColumn)
The method generates the context menu items by clickingColumn. After the process, the popup will contain all the generated menu items. You can override the method to add some new menu items or delete some existing menu items as you wish. You can use CONTEXT_MENU_... as the name to find the existing menu items.
      for (int i = 0; i < popup.getComponentCount(); i++) {
          if (CONTEXT_MENU_AUTO_RESIZE.equals(popup.getComponent(i).getName())) {
              popup.remove(popup.getComponent(i));
          }
      }
 

Specified by:
customizePopupMenu in interface TableHeaderPopupMenuCustomizer
Parameters:
header - the table header
popup - the popup menu to be displayed
clickingColumn - the column index clicked

getColumnName

protected String getColumnName(JTableHeader header,
                               int clickingColumn)
Gets the column name of the clicking column. By default, we use TableColumn#getHeaderValue but you can override it to return a customized column name. This column name will be displayed on the "Auto Resize Column" menu item if it is not null or empty.

Parameters:
header - the table header.
clickingColumn - the clicking column.
Returns:
the column name of the clicking column.

JIDE 3.5.15