Package com.jidesoft.swing
Class Resizable
- java.lang.Object
-
- com.jidesoft.swing.Resizable
-
public class Resizable extends java.lang.Object
Resizable
is a class that supports the resizable feature. To use it and make a component resizable, you just need to create new Resizable(component) and pass in that component to the constructor.Resizable
usesbeginResizing(int)
,resizing(int, int, int, int, int)
andendResizing(int)
to archive the resizing effect. It should work for most cases. However if it doesn't work as expected for some layouts, you can override one of all of the three methods to make it working.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Resizable.ResizeCorner
-
Field Summary
Fields Modifier and Type Field Description protected javax.swing.JComponent
_component
static int
ALL
static int
LEFT
static int
LOWER
static int
LOWER_LEFT
static int
LOWER_RIGHT
static int
NONE
static java.lang.String
PROPERTY_RESIZABLE_CORNERS
static java.lang.String
PROPERTY_RESIZE_CORNER_SIZE
static int
RIGHT
static int
UPPER
static int
UPPER_LEFT
static int
UPPER_RIGHT
-
Constructor Summary
Constructors Constructor Description Resizable(javax.swing.JComponent component)
Creates a newResizable
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginResizing(int resizeCorner)
This method is called when resizing operation started.protected javax.swing.event.MouseInputListener
createMouseInputListener()
Creates the MouseInputListener for resizing.void
endResizing(int resizeCorner)
The method is called when resizing ends.javax.swing.JComponent
getComponent()
Gets the component which has this Resizable object.javax.swing.event.MouseInputListener
getMouseInputAdapter()
Gets the mouse adapter for resizing.int
getResizableCorners()
Gets the resizable corners.int
getResizeCornerSize()
Gets resize corner size.java.awt.Insets
getResizeInsets()
Returns the insets that should be used to calculate the resize area.int
getSnapGridSize()
Gets the snap grid size.protected void
installListeners()
Installs the listeners needed to perform resizing operations.boolean
isTopLevel()
Checks if the Resizable is added to a top level component.void
resizing(int resizeCorner, int newX, int newY, int newW, int newH)
This method is called during the resizing of ResizablePanel.void
setResizableCorners(int resizableCorners)
Sets resizable corners.void
setResizeCornerSize(int resizeCornerSize)
Sets the resize corner size.void
setResizeInsets(java.awt.Insets resizeInsets)
Sets the insets the be used to calculate the resize area.void
setSnapGridSize(int snapGridSize)
Sets the snap grid size.void
setTopLevel(boolean topLevel)
To indicates thisResizable
is installed on a top level component such as JWindow, JDialog and JFrame v.s.void
uninstallListeners()
Uninstalls the listeners that created to perform resizing operations.
-
-
-
Field Detail
-
NONE
public static final int NONE
- See Also:
- Constant Field Values
-
UPPER_LEFT
public static final int UPPER_LEFT
- See Also:
- Constant Field Values
-
UPPER
public static final int UPPER
- See Also:
- Constant Field Values
-
UPPER_RIGHT
public static final int UPPER_RIGHT
- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
- See Also:
- Constant Field Values
-
LOWER_RIGHT
public static final int LOWER_RIGHT
- See Also:
- Constant Field Values
-
LOWER
public static final int LOWER
- See Also:
- Constant Field Values
-
LOWER_LEFT
public static final int LOWER_LEFT
- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
- See Also:
- Constant Field Values
-
ALL
public static final int ALL
- See Also:
- Constant Field Values
-
PROPERTY_RESIZABLE_CORNERS
public static final java.lang.String PROPERTY_RESIZABLE_CORNERS
- See Also:
- Constant Field Values
-
PROPERTY_RESIZE_CORNER_SIZE
public static final java.lang.String PROPERTY_RESIZE_CORNER_SIZE
- See Also:
- Constant Field Values
-
_component
protected final javax.swing.JComponent _component
-
-
Method Detail
-
getResizableCorners
public int getResizableCorners()
Gets the resizable corners. The value is a bitwise OR of eight constants defined inResizable
.- Returns:
- resizable corners.
-
setResizableCorners
public void setResizableCorners(int resizableCorners)
Sets resizable corners.- Parameters:
resizableCorners
- new resizable corners. The value is a bitwise OR of eight constants defined inResizable
.
-
getResizeCornerSize
public int getResizeCornerSize()
Gets resize corner size. This size is the corner's sensitive area which will trigger the resizing from both sides.- Returns:
- the resize corner size.
-
setResizeCornerSize
public void setResizeCornerSize(int resizeCornerSize)
Sets the resize corner size.- Parameters:
resizeCornerSize
- the resize corner size.
-
installListeners
protected void installListeners()
Installs the listeners needed to perform resizing operations. You do not need to call this method directly. Constructor will call this method automatically.
-
uninstallListeners
public void uninstallListeners()
Uninstalls the listeners that created to perform resizing operations. After the uninstallation, the component will not be resizable anymore.
-
createMouseInputListener
protected javax.swing.event.MouseInputListener createMouseInputListener()
Creates the MouseInputListener for resizing. Subclass can override this method to provide its own MouseInputListener to customize existing one.- Returns:
- the MouseInputListener for resizing.
-
getMouseInputAdapter
public javax.swing.event.MouseInputListener getMouseInputAdapter()
Gets the mouse adapter for resizing.- Returns:
- the mouse adapter for resizing.
-
beginResizing
public void beginResizing(int resizeCorner)
This method is called when resizing operation started.- Parameters:
resizeCorner
- the resize corner.
-
resizing
public void resizing(int resizeCorner, int newX, int newY, int newW, int newH)
This method is called during the resizing of ResizablePanel. In default implementation, it call
in fact, depending on where you added this ResizablePanel, you may need to override this method to do something else. For example,setPreferredSize(new Dimension(newW, newH)); getParent().doLayout();
ResizableWindow
usesResizablePanel
to implement resizable feature in JWindow. It overrides this method to call setBounds on JWindow itself.- Parameters:
resizeCorner
- the resize corner.newX
- the new x position.newY
- the new y position.newW
- the new width.newH
- the new height.
-
endResizing
public void endResizing(int resizeCorner)
The method is called when resizing ends.- Parameters:
resizeCorner
- the resize corner.
-
isTopLevel
public boolean isTopLevel()
Checks if the Resizable is added to a top level component.If it's top level component, it will use screen coordinates to do all calculations during resizing. If resizing the resizable panel won't affect any top level container's position, you can return false here. Otherwise, return true. The default implementation always return false. Subclasses can override to return different value. In the case of ResizableWindow or ResizableDialog, this method is overridden and returns true.
- Returns:
- false.
-
setTopLevel
public void setTopLevel(boolean topLevel)
To indicates thisResizable
is installed on a top level component such as JWindow, JDialog and JFrame v.s. a JPanel which is not a top level component because a JPanel must be added to another top level component in order to be displayed.- Parameters:
topLevel
- true or false.
-
getComponent
public javax.swing.JComponent getComponent()
Gets the component which has this Resizable object.- Returns:
- the component which has this Resizable object.
-
getResizeInsets
public java.awt.Insets getResizeInsets()
Returns the insets that should be used to calculate the resize area. Unless you have used setResizeInsets or overridden this method, it'll return the insets of the component.- Returns:
- the insets that should be used to calculate the resize area.
-
setResizeInsets
public void setResizeInsets(java.awt.Insets resizeInsets)
Sets the insets the be used to calculate the resize area.- Parameters:
resizeInsets
-
-
getSnapGridSize
public int getSnapGridSize()
Gets the snap grid size.- Returns:
- the snap grid size.
- See Also:
setSnapGridSize(int)
-
setSnapGridSize
public void setSnapGridSize(int snapGridSize)
Sets the snap grid size. Snap grid size is used to make resizing easier. By default, the size is 1 pixel.- Parameters:
snapGridSize
- the grid size
-
-