Changing ToolTip background color for Swing Applications : UIDefault « Swing « Java Tutorial






import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalLookAndFeel;

class MyLookAndFeel extends MetalLookAndFeel {
  protected void initSystemColorDefaults(UIDefaults table) {
    super.initSystemColorDefaults(table);
    table.put("info", new ColorUIResource(255, 255, 225));
  }
}

class Main extends JFrame {
  public Main() throws Exception{
    UIManager.setLookAndFeel("MyLookAndFeel");
    setLayout(new FlowLayout());

    JButton b = new JButton();
    b.setText("<html>A<br> B</html>");
    b.setToolTipText("<html>C<br>D<br>E</html>");

    add(b);

    JLabel l = new JLabel("Z");
    l.setToolTipText("zzzzz...");

    add(l);
  }
  public static void main(String[] arg)throws Exception {
    Main m = new Main();

    m.setVisible(true);
    m.setSize(new Dimension(300, 150));
    m.validate();
  }
}








14.121.UIDefault
14.121.1.UIDefaults ClassUIDefaults Class
14.121.2.Setting a UI Default Value That Is Created at Every Fetch
14.121.3.Setting a UI Default Value That Is Created When Fetched
14.121.4.Getting the Default Values for a Look and Feel
14.121.5.Listing UIDefault Properties
14.121.6.Changing ToolTip background color for Swing Applications
14.121.7.Get default values for Swing-based user interface