本文整理匯總了Java中javax.swing.JToolTip類的典型用法代碼示例。如果您正苦於以下問題:Java JToolTip類的具體用法?Java JToolTip怎麽用?Java JToolTip使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JToolTip類屬於javax.swing包,在下文中一共展示了JToolTip類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getToolTipLocation
import javax.swing.JToolTip; //導入依賴的package包/類
/**
* Positions tool tips to be aligned in the text component, so that the
* displayed content is shown (almost) exactly where it would be in the
* editor.
*
* @param e The mouse location.
*/
@Override
public Point getToolTipLocation(MouseEvent e) {
// ToolTipManager requires both location and text to be null to hide
// a currently-visible tool tip window. If text is null but location
// has some value, it will show a tool tip with empty content, the size
// of its border (!).
String text = getToolTipText(e);
if (text==null) {
return null;
}
// Try to overlap the tip's text directly over the code
Point p = e.getPoint();
p.y = (p.y/textArea.getLineHeight()) * textArea.getLineHeight();
p.x = getWidth() + textArea.getMargin().left;
Gutter gutter = getGutter();
int gutterMargin = gutter.getInsets().right;
p.x += gutterMargin;
JToolTip tempTip = createToolTip();
p.x -= tempTip.getInsets().left;
p.y += 16;
return p;
}
示例2: getListCellRendererComponent
import javax.swing.JToolTip; //導入依賴的package包/類
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value != null) {
JToolTip createToolTip = comp.createToolTip();
Font font = createToolTip.getFont();
FontMetrics fontMetrics = getFontMetrics(font);
int length = fontMetrics.stringWidth((String) value);
if (length < MAX_TOOLTIP_WIDTH) {
comp.setToolTipText("<html><p width=\"" + length + "\">" + value + "</p></html>");
} else {
comp.setToolTipText("<html><p width=\"" + MAX_TOOLTIP_WIDTH + "\">" + value + "</p></html>");
}
}
return comp;
}
示例3: createToolTip
import javax.swing.JToolTip; //導入依賴的package包/類
@Override
public JToolTip createToolTip() {
JToolTip t = toolTip;
toolTip = null;
if (t != null) {
t.addMouseMotionListener(new MouseMotionAdapter() { // #233642
boolean initialized = false;
@Override
public void mouseMoved(MouseEvent e) {
if (!initialized) {
initialized = true; // ignore the first event
} else {
// hide the tooltip if mouse moves over it
ToolTipManager.sharedInstance().mousePressed(e);
}
}
});
return t;
} else {
return super.createToolTip();
}
}
示例4: createToolTip
import javax.swing.JToolTip; //導入依賴的package包/類
/**
* Overridden to use the editor's background if it's detected that the
* user isn't using white as the editor bg, but the system's tool tip
* background is yellow-ish.
*
* @return The tool tip.
*/
@Override
public JToolTip createToolTip() {
JToolTip tip = super.createToolTip();
Color textAreaBG = textArea.getBackground();
if (textAreaBG!=null && !Color.white.equals(textAreaBG)) {
Color bg = TipUtil.getToolTipBackground();
// If current L&F's tool tip color is close enough to "yellow",
// and we're not using the default text background of white, use
// the editor background as the tool tip background.
if (bg.getRed()>=240 && bg.getGreen()>=240 && bg.getBlue()>=200) {
tip.setBackground(textAreaBG);
}
}
return tip;
}
示例5: showToolTip
import javax.swing.JToolTip; //導入依賴的package包/類
private void showToolTip(boolean flag) {
try {
if (flag) {
int qtd = heroi.getDeck().size();
String txt = (qtd == 0 ? "Nenhum card" : qtd == 1
? "1 card" : qtd + " cards");
Point p = getLocationOnScreen();
JToolTip tip = createToolTip();
tip.setTipText(txt);
PopupFactory popupFactory = PopupFactory.getSharedInstance();
tooltip = popupFactory.getPopup(this, tip, p.x + 10, p.y + 10);
tooltip.show();
} else {
tooltip.hide();
}
} catch (Exception ex) {
//ignorar
}
}
示例6: showToolTip
import javax.swing.JToolTip; //導入依賴的package包/類
private void showToolTip(boolean flag) {
try {
if (flag) {
int qtd = heroi.getMao().size();
String txt = (qtd == 0 ? "Nenhum card" : qtd == 1
? "1 card" : qtd + " cards");
Point p = getLocationOnScreen();
JToolTip tip = createToolTip();
tip.setTipText(txt);
PopupFactory popupFactory = PopupFactory.getSharedInstance();
tooltip = popupFactory.getPopup(this, tip, p.x + 10, p.y + 10);
tooltip.show();
} else {
tooltip.hide();
}
} catch (Exception ex) {
//ignorar
}
}
示例7: JToolTipWindowFinder
import javax.swing.JToolTip; //導入依賴的package包/類
public JToolTipWindowFinder() {
ppFinder = new ComponentChooser() {
@Override
public boolean checkComponent(Component comp) {
return (comp.isShowing()
&& comp.isVisible()
&& comp instanceof JToolTip);
}
@Override
public String getDescription() {
return "A tool tip";
}
@Override
public String toString() {
return "JComponentOperator.JToolTipWindowFinder.ComponentChooser{description = " + getDescription() + '}';
}
};
}
示例8: getPreferredSize
import javax.swing.JToolTip; //導入依賴的package包/類
@Override
public Dimension getPreferredSize(JComponent c) {
String tipText = ((JToolTip)c).getTipText();
if (tipText == null || tipText.isEmpty()) {
return new Dimension(0, 0);
}
float x = 0f;
float y = 0f;
for (String line : lineBreak.split(tipText)) {
if (line.isEmpty()) {
y += LEADING;
continue;
}
AttributedCharacterIterator styledText
= new AttributedString(line).getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);
while (measurer.getPosition() < styledText.getEndIndex()) {
TextLayout layout = measurer.nextLayout(maximumWidth);
x = Math.max(x, layout.getVisibleAdvance());
y += layout.getAscent() + layout.getDescent() + layout.getLeading();
}
}
return new Dimension((int) (x + 2 * margin),
(int) (y + 2 * margin));
}
示例9: isToolTipShowing
import javax.swing.JToolTip; //導入依賴的package包/類
private static boolean isToolTipShowing(Container container)
{
if (container instanceof Window)
{
for (Window window : ((Window) container).getOwnedWindows())
{
if (isToolTipShowing(window))
{
return true;
}
}
}
for (int i = 0; i < container.getComponentCount(); i++)
{
Component child = container.getComponent(i);
if (child instanceof JToolTip && child.isShowing()
|| child instanceof Container && isToolTipShowing((Container) child))
{
return true;
}
}
return false;
}
示例10: getPreferredSize
import javax.swing.JToolTip; //導入依賴的package包/類
/**
* This method returns the preferred size of the given JComponent.
*
* @param c The JComponent to find a preferred size for.
*
* @return The preferred size.
*/
public Dimension getPreferredSize(JComponent c)
{
JToolTip tip = (JToolTip) c;
String str = tip.getTipText();
FontMetrics fm = c.getFontMetrics(c.getFont());
Insets i = c.getInsets();
Dimension d = new Dimension(i.left + i.right, i.top + i.bottom);
if (str != null && ! str.equals(""))
{
View view = (View) c.getClientProperty(BasicHTML.propertyKey);
if (view != null)
{
d.width += (int) view.getPreferredSpan(View.X_AXIS);
d.height += (int) view.getPreferredSpan(View.Y_AXIS);
}
else
{
d.width += fm.stringWidth(str) + 6;
d.height += fm.getHeight();
}
}
return d;
}
示例11: createButton
import javax.swing.JToolTip; //導入依賴的package包/類
private JButton createButton(final ComponentDefinition comp) {
JButton button = new JButton(comp.getDisplayId(), ICON) {
public JToolTip createToolTip() {
Image image = (Image) getClientProperty("overview");
JToolTipWithIcon tip = new JToolTipWithIcon(new ImageIcon(image));
tip.setComponent(this);
return tip;
}
};
button.putClientProperty("comp", comp);
// TODO this is broken
// button.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent event) {
// try {
// design.focusOut(comp);
// } catch (SBOLValidationException e) {
// JOptionPane.showMessageDialog(null, "There was an error: " +
// e.getMessage());
// e.printStackTrace();
// }
// }
// });
Buttons.setStyle(button);
return button;
}
示例12: ToolButton
import javax.swing.JToolTip; //導入依賴的package包/類
/**
* Constructs a ToolButton object.
* @param toolName the name of the tool
* @param imageName the name of the tool button image
*/
public ToolButton(String toolName, String imageName) {
// Use JButton constructor
super(ImageLoader.getIcon(imageName));
// Initialize toolName
this.toolName = toolName;
// Initialize tool tip for button
toolButtonTip = new JToolTip();
toolButtonTip.setBackground(Color.white);
toolButtonTip.setBorder(new LineBorder(Color.yellow));
setToolTipText(toolName);
// Prepare default tool button values
setAlignmentX(.5F);
setAlignmentY(.5F);
}
示例13: setPopupFactory
import javax.swing.JToolTip; //導入依賴的package包/類
public static void setPopupFactory() {
PopupFactory.setSharedInstance(new PopupFactory() {
@Override
public Popup getPopup(Component owner, Component contents, int x, int y) throws IllegalArgumentException {
if (contents instanceof JToolTip) {
JToolTip toolTip = (JToolTip)contents;
int width = (int) toolTip.getPreferredSize().getWidth();
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int screenWidth = gd.getDisplayMode().getWidth();
// if there is enough room, move tooltip to the right to have enough room
// for large tooltips.
// this way they don't hinder mouse movement and make it possible to easily
// view multiple tooltips of items.
if (x + width + TOOLTIP_X_OFFSET < screenWidth) {
x += TOOLTIP_X_OFFSET;
}
}
return super.getPopup(owner, contents, x, y);
}
});
}
示例14: getPreferredSize
import javax.swing.JToolTip; //導入依賴的package包/類
public Dimension getPreferredSize(JComponent c) {
Font font = c.getFont();
String tipText = ((JToolTip) c).getTipText();
JToolTip mtt = (JToolTip) c;
FontMetrics fontMetrics = mtt.getFontMetrics(font);
int fontHeight = fontMetrics.getHeight();
if (tipText == null)
return new Dimension(0, 0);
String lines[] = tipText.split("\n");
int num_lines = lines.length;
int width, height, onewidth;
height = num_lines * fontHeight;
width = 0;
for (int i = 0; i < num_lines; i++) {
onewidth = fontMetrics.stringWidth(lines[i]);
width = Math.max(width, onewidth);
}
return new Dimension(width + inset * 2, height + inset * 2);
}
示例15: paint
import javax.swing.JToolTip; //導入依賴的package包/類
public void paint(Graphics g, JComponent c) {
Font font = c.getFont();
JToolTip mtt = (JToolTip) c;
FontMetrics fontMetrics = mtt.getFontMetrics(font);
Dimension dimension = c.getSize();
int fontHeight = fontMetrics.getHeight();
int fontAscent = fontMetrics.getAscent();
String tipText = ((JToolTip) c).getTipText();
if (tipText == null)
return;
String lines[] = tipText.split("\n");
int num_lines = lines.length;
int height;
int i;
g.setColor(c.getBackground());
g.fillRect(0, 0, dimension.width, dimension.height);
g.setColor(c.getForeground());
for (i = 0, height = 2 + fontAscent; i < num_lines; i++, height += fontHeight) {
g.drawString(lines[i], inset, height);
}
}