下面列出了javax.swing.JToolTip#getPreferredSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void checkSize(JToolTip tip, int width, int height) {
Dimension d = tip.getPreferredSize();
Insets insets = tip.getInsets();
//6 seems to be the extra width being allocated for some reason
//for a tooltip window.
if (!((d.width - insets.right - insets.left - 6) == width) &&
!((d.height - insets.top - insets.bottom) == height)) {
throw new RuntimeException("Test case fails: Expected width, height is " + width + ", " + height +
" whereas actual width, height are " + (d.width - insets.right - insets.left - 6) + " " +
(d.height - insets.top - insets.bottom));
}
}
private static void checkSize(JToolTip tip, int width, int height) {
Dimension d = tip.getPreferredSize();
Insets insets = tip.getInsets();
//6 seems to be the extra width being allocated for some reason
//for a tooltip window.
if (!((d.width - insets.right - insets.left - 6) == width) &&
!((d.height - insets.top - insets.bottom) == height)) {
throw new RuntimeException("Test case fails: Expected width, height is " + width + ", " + height +
" whereas actual width, height are " + (d.width - insets.right - insets.left - 6) + " " +
(d.height - insets.top - insets.bottom));
}
}
private static void checkSize(JToolTip tip, int width, int height) {
Dimension d = tip.getPreferredSize();
Insets insets = tip.getInsets();
//6 seems to be the extra width being allocated for some reason
//for a tooltip window.
if (!((d.width - insets.right - insets.left - 6) == width) &&
!((d.height - insets.top - insets.bottom) == height)) {
throw new RuntimeException("Test case fails: Expected width, height is " + width + ", " + height +
" whereas actual width, height are " + (d.width - insets.right - insets.left - 6) + " " +
(d.height - insets.top - insets.bottom));
}
}
@Override
public Point getToolTipLocation( MouseEvent event ) {
JToolTip tip = createToolTip();
tip.setTipText( getToolTipText() );
Dimension d = tip.getPreferredSize();
Point retValue = new Point( getWidth()-d.width, -d.height );
return retValue;
}
@Override
public Point getToolTipLocation(MouseEvent event) {
JToolTip tip = createToolTip();
tip.setTipText(getToolTipText());
Dimension d = tip.getPreferredSize();
Point retValue = new Point(getWidth() - d.width, -d.height);
return retValue;
}
@Override
public Point getToolTipLocation( MouseEvent event ) {
JToolTip tip = createToolTip();
tip.setTipText( getToolTipText() );
Dimension d = tip.getPreferredSize();
Point retValue = new Point( getWidth()-d.width, -d.height );
return retValue;
}
@Override
public Point getToolTipLocation(MouseEvent event) {
if (event != null) {
Point p = event.getPoint();
int index = locationToIndex(p);
ListCellRenderer r = getCellRenderer();
Rectangle cellBounds;
if (index != -1 && (r instanceof BasicTileCellRenderer)
&& (cellBounds = getCellBounds(index, index)) != null
&& cellBounds.contains(p.x, p.y)) {
String text = getToolTipText(event);
JToolTip tip = new JToolTip();
tip.setTipText(text);
Dimension tipSize = tip.getPreferredSize();
BasicTileCellRenderer btcr = (BasicTileCellRenderer) r;
int yOffset = cellBounds.height / 2;
if (btcr.thumbnail.getUI() instanceof ThumbnailLabelUI) {
ThumbnailLabelUI ui = (ThumbnailLabelUI) btcr.thumbnail
.getUI();
yOffset = ui.getTextRect().y;
}
return new Point(cellBounds.x + cellBounds.width / 2
- tipSize.width / 2, cellBounds.y + yOffset);
}
}
return super.getToolTipLocation(event);
}
private static void checkSize(JToolTip tip, int width, int height) {
Dimension d = tip.getPreferredSize();
Insets insets = tip.getInsets();
//6 seems to be the extra width being allocated for some reason
//for a tooltip window.
if (!((d.width - insets.right - insets.left - 6) == width) &&
!((d.height - insets.top - insets.bottom) == height)) {
throw new RuntimeException("Test case fails: Expected width, height is " + width + ", " + height +
" whereas actual width, height are " + (d.width - insets.right - insets.left - 6) + " " +
(d.height - insets.top - insets.bottom));
}
}