javax.swing.plaf.basic

Class BasicArrowButton

public class BasicArrowButton extends JButton implements SwingConstants

A button that displays an arrow (triangle) that points {@link #NORTH}, {@link #SOUTH}, {@link #EAST} or {@link #WEST}. This button is used by the {@link BasicComboBoxUI} class.

See Also: BasicComboBoxUI

Field Summary
protected intdirection
The direction that the arrow points.
Constructor Summary
BasicArrowButton(int direction)
Creates a new BasicArrowButton object with an arrow pointing in the specified direction.
BasicArrowButton(int direction, Color background, Color shadow, Color darkShadow, Color highlight)
Creates a new BasicArrowButton object with the given colors and direction.
Method Summary
intgetDirection()
Returns the direction of the arrow (one of: {@link #NORTH}, {@link #SOUTH}, {@link #EAST} and {@link #WEST}).
DimensiongetMaximumSize()
Returns the maximum size of the arrow button.
DimensiongetMinimumSize()
Returns the minimum size of the arrow button.
DimensiongetPreferredSize()
Returns the preferred size of the arrow button.
booleanisFocusTraversable()
Returns whether the focus can traverse to this component.
voidpaint(Graphics g)
Paints the arrow button.
voidpaintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled)
Paints a triangle with the given size, location and direction.
voidsetDirection(int dir)
Sets the direction of the arrow.

Field Detail

direction

protected int direction
The direction that the arrow points.

See Also: getDirection

Constructor Detail

BasicArrowButton

public BasicArrowButton(int direction)
Creates a new BasicArrowButton object with an arrow pointing in the specified direction. If the direction is not one of the specified constants, no arrow is drawn.

Parameters: direction The direction the arrow points in (one of: {@link #NORTH}, {@link #SOUTH}, {@link #EAST} and {@link #WEST}).

BasicArrowButton

public BasicArrowButton(int direction, Color background, Color shadow, Color darkShadow, Color highlight)
Creates a new BasicArrowButton object with the given colors and direction.

Parameters: direction The direction to point in (one of: {@link #NORTH}, {@link #SOUTH}, {@link #EAST} and {@link #WEST}). background The background color. shadow The shadow color. darkShadow The dark shadow color. highlight The highlight color.

Method Detail

getDirection

public int getDirection()
Returns the direction of the arrow (one of: {@link #NORTH}, {@link #SOUTH}, {@link #EAST} and {@link #WEST}).

Returns: The direction of the arrow.

getMaximumSize

public Dimension getMaximumSize()
Returns the maximum size of the arrow button.

Returns: The maximum size (always Integer.MAX_VALUE x Integer.MAX_VALUE).

getMinimumSize

public Dimension getMinimumSize()
Returns the minimum size of the arrow button.

Returns: The minimum size (always 5 x 5).

getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size of the arrow button.

Returns: The preferred size (always 16 x 16).

isFocusTraversable

public boolean isFocusTraversable()
Returns whether the focus can traverse to this component. This method always returns false.

Returns: false.

paint

public void paint(Graphics g)
Paints the arrow button. The painting is delegated to the paintTriangle method.

Parameters: g The Graphics object to paint with.

paintTriangle

public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled)
Paints a triangle with the given size, location and direction. It is difficult to explain the rationale behind the positioning of the triangle relative to the given (x, y) position - by trial and error we seem to match the behaviour of the reference implementation (which is missing a specification for this method).

Parameters: g the graphics device. x the x-coordinate for the triangle's location. y the y-coordinate for the triangle's location. size the arrow size (depth). direction the direction of the arrow (one of: {@link #NORTH}, {@link #SOUTH}, {@link #EAST} and {@link #WEST}). isEnabled if true the arrow is drawn in the enabled state, otherwise it is drawn in the disabled state.

setDirection

public void setDirection(int dir)
Sets the direction of the arrow.

Parameters: dir The new direction of the arrow (one of: {@link #NORTH}, {@link #SOUTH}, {@link #EAST} and {@link #WEST}).