JToolTip เป็นคลาสย่อยของ JComponent class และเราสามารถสร้าง tooltip สำหรับส่วนประกอบ java โดยใช้ setToolTipText() เมธอด สามารถใช้เพื่อตั้งค่าคำแนะนำเครื่องมือสำหรับส่วนประกอบ วิธีการที่สำคัญของคลาส JToolTip คือ getAccessibleContext(), getComponent(), paramString() และ updateUI() . เราสามารถเปลี่ยนทั้งสีพื้นหลังและพื้นหน้าของคลาส JToolTip โดยใช้ put() วิธีการของ UIManager คลาสและส่งอาร์กิวเมนต์ ToolTip.background และ ToolTip.foreground
ตัวอย่าง
import java.awt.*;
import javax.swing.*;
public class JTooltipColorTest extends JFrame {
private JLabel label;
public JTooltipColorTest() {
setTitle("JTooltipColor Test");
setLayout(new FlowLayout());
label = new JLabel("Welcome to TutorialsPoint");
label.setToolTipText("Simply Easy Learning");
UIManager.put("ToolTip.background", Color.white); // to change background color of a JTtoolTip
UIManager.put("ToolTip.foreground", Color.green); // to change foreground color of a JToolTip
add(label);
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
new JTooltipColorTest();
}
} ผลลัพธ์
