public void setFont(Font font) { super.setFont(font); fontMetrics = this.getFontMetrics(font); fontHeight = fontMetrics.getHeight(); descent = fontMetrics.getDescent(); drawFont = font; }
@Override public void setFont(Font font) { super.setFont(font); fontMetrics = this.getFontMetrics(font); fontHeight = fontMetrics.getHeight(); ascent = fontMetrics.getAscent(); drawFont = font; }
public class Main { public static void main(String args[]) { JFrame frame = new JFrame("JToolTip Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton b1 = new JButton("Button 1") { public JToolTip createToolTip() { JToolTip tip = super.createToolTip(); tip.setForeground(Color.YELLOW); tip.setBackground(Color.RED); tip.setFont(new Font("Arial", Font.BOLD,36)); return tip; } }; b1.setToolTipText("HELLO"); frame.add(b1, BorderLayout.NORTH); frame.setSize(300, 150); frame.setVisible(true); } }
public class CButton extends JButton { public CButton(String text, Icon icon) { super(text, icon); } @Override public JToolTip createToolTip() { JToolTip toolTip = super.createToolTip(); toolTip.setForeground(Color.BLACK); toolTip.setBackground(Color.WHITE); toolTip.setFont(new Font("Arial", Font.PLAIN, 12)); return toolTip; } };
/** * Creates a tool tip with the label's font. */ @Override public JToolTip createToolTip() { final JToolTip tt = super.createToolTip(); tt.setFont( getFont() ); return tt; }
/** * Create a tool tip with the same font that is used in the tree. */ @Override public JToolTip createToolTip() { final JToolTip tt = super.createToolTip(); tt.setFont( getFont().deriveFont( (float) LEnv.LAUNCHER_SETTINGS.get( LSettings.PAGE_LIST_FONT_SIZE ) ) ); return tt; } };
/** * Creates a new tooltip. If overlapping is true then the tooltip will take on the foreground/background color and * font of the specified component (if the component isspecifiedd) * * @param c the component the tooltip describes * @param overlapping whether the tooltip is for a normal or overlapping tooltip * @return the new tooltip object */ public JToolTip createToolTip(JComponent c, boolean overlapping) { JToolTip tt = new JToolTip(); if (c != null) { tt.setComponent(c); if (overlapping) { if (c.getBackground() != null) { Color bg = c.getBackground(); if (bg.getAlpha() != 255) { bg = new Color(bg.getRed(), bg.getGreen(), bg.getBlue()); } tt.setBackground(bg); } if (c.getForeground() != null) { tt.setForeground(c.getForeground()); } if (c.getFont() != null) { tt.setFont(c.getFont()); } } } return tt; }