谢谢!请具体的讲一下。
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MultiLineToolTipExample extends JFrame {
public MultiLineToolTipExample() {
super("Multi-Line ToolTip Example");
JButton button = new JButton ("Hello, world") {
public JToolTip createToolTip() {
MultiLineToolTip tip = new MultiLineToolTip();
tip.setComponent(this);
return tip;
}
};
button.setToolTipText("Hellonworld");
getContentPane().add(button);
}
public static void main (String args[]) {
MultiLineToolTipExample f = new MultiLineToolTipExample();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setSize (300, 100);
f.show();
}
}
import java.awt.*;
import javax.swing.*;
public class MultiLineToolTip extends JToolTip {
public MultiLineToolTip() {
setUI(new MultiLineToolTipUI());
}
}
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;
/**
* @version 1.0 11/09/98
*/
public class MultiLineToolTipUI extends MetalToolTipUI {
private String[] strs;
private int maxWidth = 0;
public void paint(Graphics g, JComponent c) {
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(g.getFont());
Dimension size = c.getSize();
g.setColor(c.getBackground());
g.fillRect(0, 0, size.width, size.height);
g.setColor(c.getForeground());
if (strs != null) {
for (int i=0;i
您可能感兴趣的文章: