|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ehsbe.commons.gui.JxTitledBorder
public class JxTitledBorder
Draws a title (if set) with a [gradient] background.
NOTE: If you change a property of the border after the border has been set to a component, you should revalidate() the component, if the property change caused a change wrt. to the insets of this border (usually caused by setting another position or font). After that, you should repaint() the component. If this is the only border of the component and insets have not been changed (foreground, background, title), you may restrict the paint to the border insets or call directly the borders paint method.
E.g.
JPanel p = new JPanel(); JxTitledBorder b = new JxTitledBorder(" "); p.setBorder(b); // ... b.setTitle("another none-empty string"); Point2D p1 = new Point2D.Float(0, 0); Point2D p2 = new Point2D.Float(1.5f, 0); b.setBackground(new GradientPaint(p1, Color.RED, p2, Color.YELLOW)); b.paintBorder(p, 0, 0, p.getWidth(), p.getHeight());
Field Summary | |
---|---|
protected static int |
TEXT_GAP_H
gap on top and on the bottom of the title |
protected static int |
TEXT_GAP_V
gap on top and on the bottom of the title |
protected BufferedImage |
tmpBackground
cache for gradient background |
protected Paint |
tmpForeground
cached value from getForeground() |
Constructor Summary | |
---|---|
JxTitledBorder()
Create a Border without a title |
|
JxTitledBorder(String title)
Create a border with the given title |
|
JxTitledBorder(String title,
int horizontalAlignment)
Create a border with the given title and alignment |
|
JxTitledBorder(String title,
int horizontalAlignment,
int position)
Create a border with the given title and alignment and position |
Method Summary | |
---|---|
static GradientPaint |
adjustGradient(GradientPaint gp,
int width,
int height)
Calculate a new GradientPaint wrt. to the settings of the given gp, but adjust it to the current size of this component. |
static GradientPaint |
createGradient(Color dark,
Color light)
Create a default Gradient adjusted to the given width. |
int |
getAlignment()
Get the horizontal alignment of the title. |
Paint |
getBackground()
|
Insets |
getBorderInsets(Component c)
|
Font |
getFont()
|
Paint |
getForeground()
|
static com.ehsbe.commons.gui.JxTitledBorder.PaintType |
getPaintType(Paint paint)
Determine the type of a paint object. |
int |
getPosition()
|
String |
getTitle()
|
boolean |
isBorderOpaque()
|
static boolean |
isGradient(com.ehsbe.commons.gui.JxTitledBorder.PaintType type)
Check, whether the given paint type is a gradient paint. |
protected void |
paintBackground(Graphics2D g2d,
int xs,
int ys,
int ws,
int hs)
Convinience method to draw the background. |
void |
paintBorder(Component c,
Graphics g,
int x,
int y,
int width,
int height)
|
void |
setAlignment(int horizontalAlignment)
Set the horizontal alignment of the title. |
void |
setBackground(Paint background)
|
void |
setFont(Font font)
|
void |
setForeground(Paint foreground)
|
protected void |
setForegroundPaint(Graphics2D g2d,
int width,
int height)
Convinience method to set the foreground paint within a paint method to reduce redundant code. |
void |
setPosition(int position)
|
void |
setTitle(String title)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static int TEXT_GAP_V
protected static int TEXT_GAP_H
protected transient BufferedImage tmpBackground
protected transient Paint tmpForeground
getForeground()
Constructor Detail |
---|
public JxTitledBorder()
public JxTitledBorder(String title)
title
- title to usepublic JxTitledBorder(String title, int horizontalAlignment)
title
- title to set.horizontalAlignment
- SwingConstants.LEFT
| SwingConstants.CENTER
|
SwingConstants.RIGHT
public JxTitledBorder(String title, int horizontalAlignment, int position)
title
- title to set.horizontalAlignment
- SwingConstants.LEFT
| SwingConstants.CENTER
|
SwingConstants.RIGHT
position
- SwingConstants.TOP
| SwingConstants.LEFT
|
SwingConstants.BOTTOM
| SwingConstants.RIGHT
Method Detail |
---|
public boolean isBorderOpaque()
isBorderOpaque
in interface Border
public static GradientPaint adjustGradient(GradientPaint gp, int width, int height)
The first point in the user space is the vector product of the first point in user space of the given Paint gp and this components current width and height.
The second point in the user space is the vector product of the second point in user space of the given Paint gp and this components current width and height.
Colors and [none-]linearity are kept as they are in the given Paint gp.
gp
- the originalwidth
- the width of the borderheight
- the height of the border part used to draw the title
public static com.ehsbe.commons.gui.JxTitledBorder.PaintType getPaintType(Paint paint)
paint
- the paint to analyze
public static boolean isGradient(com.ehsbe.commons.gui.JxTitledBorder.PaintType type)
type
- the paint type
true
, if the given paint type indicates a gradient
paint.protected void setForegroundPaint(Graphics2D g2d, int width, int height)
g2d
- context, where the foreground paint should be set.width
- to which width the gradient should be adjustedheight
- to which height the gradient should be adjustedgetForeground()
,
Graphics2D.setPaint(java.awt.Paint)
protected void paintBackground(Graphics2D g2d, int xs, int ys, int ws, int hs)
If the background for this component is not set, it does nothing.
If the g2d is not a batik graphics context and the set background is a Gradient, a buffered image is setup with the size of the component and filled with the gradient,adjusted to the size of this component. This image is cached and will be reused for drawing the background to the g2d as long as the component was not invalidated.
g2d.fillRect(0, 0, this.width, this.height)
is used to
fill the appropriate area, so make sure, you have translated
the component to the correct location, before calling this method.
g2d
- graphics contextxs
- start position xys
- start position yws
- width to painths
- height to paint
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
paintBorder
in interface Border
public Insets getBorderInsets(Component c)
getBorderInsets
in interface Border
public int getAlignment()
public void setAlignment(int horizontalAlignment)
horizontalAlignment
- SwingConstants.LEFT
| SwingConstants.CENTER
|
SwingConstants.RIGHT
public static GradientPaint createGradient(Color dark, Color light)
dark
- color to use for the darker part of the gradientlight
- color to use for the lighter part of the gradient
public Paint getBackground()
public void setBackground(Paint background)
background
- background to set.public Font getFont()
public void setFont(Font font)
font
- font to set.public Paint getForeground()
public void setForeground(Paint foreground)
foreground
- foreground to set.public int getPosition()
public void setPosition(int position)
position
- position to set.public String getTitle()
public void setTitle(String title)
title
- title to set.
|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |