本文整理匯總了Java中javax.swing.JToolTip.setPreferredSize方法的典型用法代碼示例。如果您正苦於以下問題:Java JToolTip.setPreferredSize方法的具體用法?Java JToolTip.setPreferredSize怎麽用?Java JToolTip.setPreferredSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JToolTip
的用法示例。
在下文中一共展示了JToolTip.setPreferredSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createToolTip
import javax.swing.JToolTip; //導入方法依賴的package包/類
/**
* Generates the {@code JToolTip} with the colony's
* detailed population information.
*
* @return The JToolTip created.
*/
@Override
public JToolTip createToolTip() {
JToolTip toolTip = new RebelToolTip(getFreeColClient(), getColony());
toolTip.setPreferredSize(new Dimension(400, 185));
return toolTip;
}
示例2: createToolTip
import javax.swing.JToolTip; //導入方法依賴的package包/類
@Nullable
public JComponent createToolTip(MouseEvent e) {
final DebuggerTreeNodeImpl node = getNodeToShowTip(e);
if (node == null) {
return null;
}
if (myCurrentTooltip != null && myCurrentTooltip.isShowing() && myCurrentTooltipNode == node) {
return myCurrentTooltip;
}
myCurrentTooltipNode = node;
final String toolTipText = getTipText(node);
if (toolTipText == null) {
return null;
}
final JComponent tipContent = createTipContent(toolTipText, node);
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(tipContent);
scrollPane.setBorder(null);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
final Point point = e.getPoint();
SwingUtilities.convertPointToScreen(point, e.getComponent());
Rectangle tipRectangle = new Rectangle(point, tipContent.getPreferredSize());
final Rectangle screen = ScreenUtil.getScreenRectangle(point.x, point.y);
final JToolTip toolTip = new JToolTip();
tipContent.addMouseListener(new HideTooltip(toolTip));
final Border tooltipBorder = toolTip.getBorder();
if (tooltipBorder != null) {
final Insets borderInsets = tooltipBorder.getBorderInsets(this);
tipRectangle
.setSize(tipRectangle.width + borderInsets.left + borderInsets.right, tipRectangle.height + borderInsets.top + borderInsets.bottom);
}
toolTip.setLayout(new BorderLayout());
toolTip.add(scrollPane, BorderLayout.CENTER);
tipRectangle.height += scrollPane.getHorizontalScrollBar().getPreferredSize().height;
tipRectangle.width += scrollPane.getVerticalScrollBar().getPreferredSize().width;
final int maxWidth = (int)(screen.width - screen.width * .25);
if (tipRectangle.width > maxWidth) {
tipRectangle.width = maxWidth;
}
final Dimension prefSize = tipRectangle.getSize();
ScreenUtil.cropRectangleToFitTheScreen(tipRectangle);
if (prefSize.width > tipRectangle.width) {
final int delta = prefSize.width - tipRectangle.width;
tipRectangle.x -= delta;
if (tipRectangle.x < screen.x) {
tipRectangle.x = screen.x + maxWidth / 2;
tipRectangle.width = screen.width - maxWidth / 2;
}
else {
tipRectangle.width += delta;
}
}
toolTip.setPreferredSize(tipRectangle.getSize());
myCurrentTooltip = toolTip;
return myCurrentTooltip;
}