Results 1 to 8 of 8
- 02-27-2010, 01:06 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
-
One way is to override the createToolTip method of your JComponent that is showing the text. For e.g.,
Java Code:import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; public class ToolTipTextColor { private static void createAndShowUI() { JPanel tooltipPanel = new JPanel() { @Override public JToolTip createToolTip() { JToolTip tooltip = super.createToolTip(); tooltip.setFont(tooltip.getFont().deriveFont(Font.BOLD, 32)); tooltip.setForeground(Color.blue); tooltip.setOpaque(false); return tooltip; } }; tooltipPanel.setPreferredSize(new Dimension(100, 100)); tooltipPanel.setBackground(Color.pink); tooltipPanel.setToolTipText("hello"); JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(400, 300)); panel.add(tooltipPanel); JFrame frame = new JFrame("ToolTipTextColor"); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } }
- 02-27-2010, 01:43 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
cool.. thanx for the solution. I appreciate your presence out there. for us.
-
Your welcome. The other solution, and the one to use if you want to change the color of the font of all the tool tips in your app is to change the look and feel default foreground color for tooltips via the UIManager. For more on this, and to see which property to change, I refer you to Rob Camick's article in his indispensable blog that you can find here: UIManager Defaults « Java Tips Weblog
If you're smart, you'll bookmark this site.
- 02-27-2010, 04:59 PM #5
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
private static void createAndShowUI() {
JPanel tooltipPanel = new JPanel() {
@Override
public JToolTip createToolTip() {
JToolTip tooltip = super.createToolTip();
tooltip.setFont(tooltip.getFont().deriveFont(Font. BOLD, 32));
tooltip.setForeground(Color.blue);
tooltip.setOpaque(false);
return tooltip;
}
};
Buddy I didn't understand this much of your coding ..... you added a panel on a panel on a frame..
JPanel tooltipPanel = new JPanel() {/**/ };
what this statement actually means?? i mean {}; i never used these after "JPanel()".
and the rest of the quoted code .. plz explain
-
I'm subclassing JPanel but doing it anonymously -- not giving the class a name and doing it inside of another class. It's similar to doing this:
Look up in this forum and elsewhere use of anonymous inner classes for more information.Java Code:class MyPanel extends JPanel { public JToolTip createToolTip() { JToolTip tooltip = super.createToolTip(); tooltip.setFont(tooltip.getFont().deriveFont(Font.BOLD, 32)); tooltip.setForeground(Color.blue); tooltip.setOpaque(false); return tooltip; } }
- 02-27-2010, 05:36 PM #7
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
Java Code:import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.plaf.ColorUIResource; public class Demo extends JPanel { Demo() { UIManager.put("ToolTip.background", new ColorUIResource(255, 255, 255)); setToolTipText("<html>This is also a way <br>to change the color<br> of the tooltip in your <br>application!</html>"); } public static void main(String[] args) { javax.swing.JFrame frame = new javax.swing.JFrame("Two-Dimensional Graph Sketcher"); frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); frame.add(new Demo()); frame.setSize(100, 100); frame.setVisible(true); } }
-
Similar Threads
-
[COLOR="Navy"]execute .bat file in mysql [/COLOR]
By msankar.ravi in forum NetworkingReplies: 0Last Post: 02-24-2010, 04:27 AM -
How to change my form design from "metal" to "nimbus" in Netbeans 6.7.1?
By mlibot in forum New To JavaReplies: 1Last Post: 01-21-2010, 09:20 AM -
problem with argument list and precedence "(" and ")"
By helpisontheway in forum Advanced JavaReplies: 6Last Post: 12-24-2009, 07:50 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks