|
qflib 0.99 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.qfs.lib.gui.SwingUtil
A collection of utilities and Swing problem workarounds that go beyond
SwingUtilities
.
Nested Class Summary | |
static class |
SwingUtil.ConstrainedViewport
This class extends JViewport to restrict the arguments passed to setViewPosition to nonnegative
coordinates. |
static class |
SwingUtil.FocusDisabler
Visitor that disables the focus for JDK 1.4 JScrollBars. |
static interface |
SwingUtil.UnsafeRunnable
This interface is similar to Runnable, except that the run method may return a value and throw any kind of Exception. |
Field Summary | |
static int |
ALL_EVENTS
Identifier for all events. |
static int |
INPUT_EVENTS
Identifier for input events. |
static int |
NO_EVENTS
Identifier for no events. |
static int |
OTHER_EVENTS
Identifier for the rest of the events. |
static int |
PAINT_EVENTS
Identifier for paint events. |
Constructor Summary | |
SwingUtil()
|
Method Summary | |
static void |
autoSizeTableColumn(javax.swing.JTable table,
int column)
Resize a table column so its fits exactly the broadest of its visible cells. |
static void |
centerWindow(java.awt.Window win)
Place a window in the center of the screen. |
static void |
centerWindowOnComponent(java.awt.Window win,
java.awt.Component com,
boolean constrain)
Place a window in the center of a component. |
static void |
cleanup(java.awt.Component c)
Break up a Component hierarchy to increase chances for garbage collection. |
static void |
closeOnEscape(java.awt.Window win)
Add a KeyboardListener to a Window that posts a WINDOW_CLOSING event on it when Escape is pressed. |
static boolean |
collapseAll(javax.swing.JTree tree,
javax.swing.tree.TreePath path,
int limit)
Collapse a tree node and all its child nodes recursively. |
static void |
constrainScroll(javax.swing.JScrollPane scrollPane)
Constrain the scrolling range of a JScrollPane so that it never scrolls to a negative view position. |
static void |
deactivateInputContexts(java.awt.Window win)
There's a problem: The AWT keeps around all the owned dialogs and disposes these when the frame is disposed. |
static void |
disableScrollBarFocus(java.awt.Component com)
Traverse a component hierarchy and make all JScrollBars non-focusable. |
static boolean |
expandAll(javax.swing.JTree tree,
javax.swing.tree.TreePath path,
int limit)
Expand a tree node and all its child nodes recursively. |
static void |
focusLater(java.awt.Component com)
A delayed version of the requestFocus method, a workaround for some weird JDK 1.4.1/Motif focus
behavior that messes up focus requests after closing a modal dialog. |
static boolean |
invokeAndWait(java.lang.Runnable runnable)
Invoke a thread inside the swing EventLoop and wait for it to finish. |
static void |
prepareKeymaps()
Prepare Keymaps of JTextField and JPasswordField, so that the return key invokes a possible default button. |
static void |
scrollDownLine(javax.swing.JScrollPane scrollPane)
Scroll the contents of a scrollPane down by one line if possible. |
static void |
scrollUpLine(javax.swing.JScrollPane scrollPane)
Scroll the contents of a scrollPane up by one line if possible. |
static void |
setDefaultEnterBinding(javax.swing.text.JTextComponent text)
Restore the default binding for the return key, if it was changed by prepareKeymaps . |
static void |
showPopup(javax.swing.JPopupMenu menu,
java.awt.Component parent,
int x,
int y,
boolean constrain)
Bring up a JPopupMenu but make sure that it is fully visible on the screen (if at all possible). |
static java.lang.Object |
withEvents(SwingUtil.UnsafeRunnable runnable,
boolean noInput)
Deprecated. Please use withEvents instead. |
static java.lang.Object |
withEvents(SwingUtil.UnsafeRunnable runnable,
int delay,
int discard)
Execute some code in a background thread, while continuing to handle AWT events from the current tread. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int NO_EVENTS
public static final int ALL_EVENTS
public static final int PAINT_EVENTS
public static final int INPUT_EVENTS
public static final int OTHER_EVENTS
Constructor Detail |
public SwingUtil()
Method Detail |
public static boolean invokeAndWait(java.lang.Runnable runnable)
runnable
- The Runnable to invoke.
public static java.lang.Object withEvents(SwingUtil.UnsafeRunnable runnable, boolean noInput) throws java.lang.reflect.InvocationTargetException
withEvents
instead.
runnable
- The UnsafeRunnable to execute.noInput
- If true, InputEvents will be discarded.
java.lang.RuntimeException
- If runnable's run method
throws a RuntimeException, it is ismply passed on
java.lang.reflect.InvocationTargetException
- If runnable's run method*
throws an Exception.public static java.lang.Object withEvents(SwingUtil.UnsafeRunnable runnable, int delay, int discard) throws java.lang.reflect.InvocationTargetException
This method distinguishes between three kinds of events identified by
This method is more or less reentrant, meaning that recusive calls don't fail horribly, but they can lead to confusion since the last call will determine the delayed and discarded event types for all calls.
runnable
- The UnsafeRunnable to execute.delay
- Binary OR of event types that should be
delayed.discard
- Binary OR of event types that should be
discarded.
java.lang.RuntimeException
- If runnable's run method
throws a RuntimeException, it is ismply passed on
java.lang.reflect.InvocationTargetException
- If runnable's run method*
throws an Exception.public static void prepareKeymaps()
setDefaultEnterBinding
.
public static void setDefaultEnterBinding(javax.swing.text.JTextComponent text)
prepareKeymaps
.
text
- The TextComponent for which to restore the binding.public static void closeOnEscape(java.awt.Window win)
win
- public static void constrainScroll(javax.swing.JScrollPane scrollPane)
JScrollPane
so that it never scrolls to a negative view position. This
helps fix a bug in the Swing 1.1.1 action for PageDown in a JTree
that places the tree at the bottom of the
JScrollPane if its size is less than the visible area.
This method replaces the JScrollPane's JViewport
with one that checks the argument to setViewPosition
.
scrollPane
- The JScrollPane to adapt.public static void showPopup(javax.swing.JPopupMenu menu, java.awt.Component parent, int x, int y, boolean constrain)
menu
- The JPopupMenu to show.parent
- The parent Component of the menu.x
- The targeted x coordinate.y
- The targeted y coordinate.constrain
- Whether the menu should be constrained to its parent
window.public static void scrollUpLine(javax.swing.JScrollPane scrollPane)
scrollPane
- The scroll pane to scroll.public static void scrollDownLine(javax.swing.JScrollPane scrollPane)
scrollPane
- The scroll pane to scroll.public static void disableScrollBarFocus(java.awt.Component com)
com
- The root of the hierarchy.public static void focusLater(java.awt.Component com)
requestFocus
method, a workaround for some weird JDK 1.4.1/Motif focus
behavior that messes up focus requests after closing a modal dialog.
com
- The component to request the focus for.public static void cleanup(java.awt.Component c)
c
- The root of the hierarchy to break up.public static void deactivateInputContexts(java.awt.Window win)
win
- The window whose InputContexts to clear.public static boolean expandAll(javax.swing.JTree tree, javax.swing.tree.TreePath path, int limit)
tree
- The tree whose nodes to expand.path
- Path to the node to start at.limit
- Maximum number of nodes to expand.
public static boolean collapseAll(javax.swing.JTree tree, javax.swing.tree.TreePath path, int limit)
tree
- The tree whose nodes to collapse.path
- Path to the node to start at.limit
- Maximum number of nodes to expand.
public static void autoSizeTableColumn(javax.swing.JTable table, int column)
table
- The table that contains the column.column
- The colunm index in table coordinates.public static void centerWindow(java.awt.Window win)
win
- The window.public static void centerWindowOnComponent(java.awt.Window win, java.awt.Component com, boolean constrain)
win
- The window.com
- The component to center on.constrain
- Whether to constrain the window to the visible
screen.
|
qflib 0.99 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |