swing components-透明ToolTip
效果:
代碼:
import ?java.awt.Color;
import ?java.awt.FlowLayout;
import ?javax.swing.JButton;
import ?javax.swing.JFrame;
import ?javax.swing.JToolTip;
/**
?*? @author ?Azure
?*? @version ?1.0?12/03/07
? */
public ? class ?AzOpaqueToolTipExample? extends ?JFrame?{
???? public ?AzOpaqueToolTipExample()?{
????????init();
????}
???? public ? void ?init()?{
???????? this .setLayout( new ?FlowLayout());
????????JButton?but? = ? new ?JButton( " 金 " )?{
???????????? public ?JToolTip?createToolTip()?{
????????????????JToolTip?tip? = ? super .createToolTip();
????????????????tip.setForeground(Color.RED);
???????????????? // ?設(shè)置ToolTip為透明
????????????????tip.setOpaque( false );
???????????????? return ?tip;
????????????}
????????};
????????but.setToolTipText( " 你懂的太早,我想的太少! " );
???????? this .add(but);
???????? this .add( new ?JButton( " 木 " ));
???????? this .add( new ?JButton( " 水 " ));
???????? this .add( new ?JButton( " 火 " ));
???????? this .add( new ?JButton( " 土 " ));
???????? this .setSize( 200 ,? 200 );
???????? this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
???????? this .setLocationRelativeTo( null );
???????? this .setVisible( true );
????}
???? public ? static ? void ?main(String?args[])?{
???????? new ?AzOpaqueToolTipExample();
????}
????
}
posted on 2007-03-12 23:31 azure 閱讀(2321) 評(píng)論(8) 編輯 收藏