ToolTippublic class ToolTip extends Window
Fields Summary |
---|
private static final int | MARGIN_HORZ | private static final int | MARGIN_VERT | private String[] | arrStrings |
Constructors Summary |
---|
public ToolTip(String strText)Constructs the ToolTip object.
super ( new Frame() );
Font font;
arrStrings = new String [1];
arrStrings[0] = new String ( strText );
font = new Font ( "Helvetica", Font.PLAIN, 10 );
this.setFont ( font );
resizePopup ();
| public ToolTip(String[] arrStrings)Constructs the ToolTip object.
super ( new Frame() );
int i;
Font font;
arrStrings = new String [arrStrings.length];
for ( i = 0; i < arrStrings.length; i++ )
arrStrings[i] = new String ( arrStrings[i] );
font = new Font ( "Helvetica", Font.PLAIN, 10 );
this.setFont ( font );
resizePopup ();
|
Methods Summary |
---|
public void | paint(java.awt.Graphics graphics)This method is called, when the window needs redrawing.
int i;
Rectangle rect;
int nX, nY;
int nHeight;
Font font;
FontMetrics fontMetrics;
rect = getBounds ();
font = getFont ();
fontMetrics = getFontMetrics ( font );
graphics.setColor ( new Color(255,255,192) );
graphics.fillRect ( 0, 0, rect.width, rect.height );
graphics.setColor ( Color.black );
graphics.drawRect ( 0, 0, rect.width-1, rect.height-1 );
nX = MARGIN_HORZ;
nY = MARGIN_VERT + fontMetrics.getAscent ();
nHeight = fontMetrics.getHeight ();
for ( i = 0; i < arrStrings.length; i++ ) {
graphics.drawString ( arrStrings[i], nX, nY );
nY += nHeight;
}
| private void | resizePopup()This method resizes window to fit all strings.
int i;
int nWidth = 0;
int nHeight = 0;
int nWidthText;
Rectangle rect;
Font font;
FontMetrics fontMetrics;
Dimension dim;
rect = getBounds ();
font = getFont ();
fontMetrics = getFontMetrics ( font );
for ( i = 0; i < arrStrings.length; i++ ) {
nWidthText = fontMetrics.stringWidth ( arrStrings[i] );
nWidth = Math.max ( nWidth, nWidthText );
}
nHeight = fontMetrics.getHeight() * arrStrings.length;
rect.width = nWidth + 2 * MARGIN_HORZ;
rect.height = nHeight + 2 * MARGIN_VERT;
dim = this.getSize ();
if ( dim.height != rect.height || rect.width > dim.width || rect.width < dim.width / 2 )
setBounds ( rect );
| public void | setText(java.lang.String strText)
arrStrings = new String [1];
arrStrings[0] = new String ( strText );
resizePopup ();
repaint ();
|
|