|
SoftNet-Consult Java Utility Library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JComboBox com.softnetConsult.utils.swing.ResizablePopupComboBox
public class ResizablePopupComboBox
Implements a JComboBox that dynamically adjusts the size of its selection drop-down based on the assumption that all items will be displayed using their toString method.
This product includes software developed by the
SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.
File: ResizablePopupComboBox.java
Library API version: "2.02"
Java compliance version: "1.5"
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library
project and its contributors.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JComboBox |
---|
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
private java.awt.Dimension |
maxPopupSize
|
private java.awt.Dimension |
minPopupSize
|
private java.awt.Dimension |
prefPopupSize
|
Fields inherited from class javax.swing.JComboBox |
---|
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
ResizablePopupComboBox()
Directly calls JComboBox.JComboBox() . |
|
ResizablePopupComboBox(javax.swing.ComboBoxModel model)
Directly calls JComboBox.JComboBox(ComboBoxModel) . |
|
ResizablePopupComboBox(java.lang.Object[] items)
Directly calls JComboBox.JComboBox(Object[]) . |
|
ResizablePopupComboBox(java.util.Vector<?> items)
Directly calls JComboBox.JComboBox(Vector) . |
Method Summary | |
---|---|
private java.awt.Dimension |
calcPopupSize()
Gets the actual size for the drop-down popup component of this combo box. |
void |
firePopupMenuWillBecomeVisible()
|
private javax.swing.plaf.basic.BasicComboPopup |
getComboPopup()
Gets the drop-down popup component for this combo box. |
java.awt.Dimension |
getMaximumPopupSize()
Gets the maximum size for this combo box drop-down popup. |
java.awt.Dimension |
getMinimumPopupSize()
Gets the minimum size for this combo box drop-down popup. |
void |
setMaximumPopupSize(java.awt.Dimension dim)
Sets the maximum size for this combo box drop-down popup. |
void |
setMaximumPopupSize(int width,
int height)
Sets the maximum size for this combo box drop-down popup. |
void |
setMinimumPopupSize(java.awt.Dimension dim)
Sets the minimum size for this combo box drop-down popup. |
void |
setMinimumPopupSize(int width,
int height)
Sets the minimum size for this combo box drop-down popup. |
private void |
setPopupSize()
Calculates the size for the popup of this compo box using calcPopupSize() and sets
that as the new drop-down popup size. |
java.awt.Dimension |
setPreferredPopupSize()
Gets the preferred size for this combo box drop-down popup. |
void |
setPreferredPopupSize(java.awt.Dimension dim)
Sets the preferred size for this combo box drop-down popup. |
void |
setPreferredPopupSize(int width,
int height)
Sets the preferred size for this combo box drop-down popup. |
void |
updateUI()
|
Methods inherited from class javax.swing.JComboBox |
---|
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.awt.Dimension minPopupSize
private java.awt.Dimension maxPopupSize
private java.awt.Dimension prefPopupSize
Constructor Detail |
---|
public ResizablePopupComboBox()
JComboBox.JComboBox()
.
public ResizablePopupComboBox(javax.swing.ComboBoxModel model)
JComboBox.JComboBox(ComboBoxModel)
.
model
- the ComboBoxModel
that provides the displayed list of items.public ResizablePopupComboBox(java.lang.Object[] items)
JComboBox.JComboBox(Object[])
.
items
- an array of objects to insert into the combo box.public ResizablePopupComboBox(java.util.Vector<?> items)
JComboBox.JComboBox(Vector)
.
items
- an vector of objects to insert into the combo box.Method Detail |
---|
public void setMinimumPopupSize(int width, int height)
0
will be interpreted as unspecified or any.
width
- The minimum width of the popup.height
- The minimum height of the popup.public void setMinimumPopupSize(java.awt.Dimension dim)
null
or component values that are smaller than 0
will be interpreted
as unspecified or any.
dim
- The minimum size for this combo box drop-down popuppublic java.awt.Dimension getMinimumPopupSize()
null
or component values that are smaller than 0
will be interpreted
as unspecified or any.public void setMaximumPopupSize(int width, int height)
0
will be interpreted as unspecified or any.
width
- The maximum width of the popup.height
- The maximum height of the popup.public void setMaximumPopupSize(java.awt.Dimension dim)
null
or component values that are smaller than 0
will be interpreted
as unspecified or any.
dim
- The maximum size for this combo box drop-down popuppublic java.awt.Dimension getMaximumPopupSize()
null
or component values that are smaller than 0
will be interpreted
as unspecified or any.public void setPreferredPopupSize(int width, int height)
0
will be interpreted as unspecified or any.
width
- The preferred width of the popup.height
- The preferred height of the popup.public void setPreferredPopupSize(java.awt.Dimension dim)
null
or component values that are smaller than 0
will be interpreted
as unspecified or any.
dim
- The preferred size for this combo box drop-down popuppublic java.awt.Dimension setPreferredPopupSize()
null
or component values that are smaller than 0
will be interpreted
as unspecified or any.public void firePopupMenuWillBecomeVisible()
firePopupMenuWillBecomeVisible
in class javax.swing.JComboBox
public void updateUI()
updateUI
in class javax.swing.JComboBox
private javax.swing.plaf.basic.BasicComboPopup getComboPopup()
private java.awt.Dimension calcPopupSize()
null
or because
their width
or height
components are set to negative values, than
the size is determined as follows:.toString()
methods. The width of the popup
is set to the width of the longest item string under the current font metrics
plus the width of the popup scroller it that is visible.
private void setPopupSize()
calcPopupSize()
and sets
that as the new drop-down popup size.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |