2

yellow window

How can i create button, when you go across with mouse show that yellow window.

Open.setToolTipText (Open); // how change it from blue to yellow?
Luka Toni
  • 187
  • 5
  • 15
  • 3
    It's called a tooltip that is used when the user hovers over a JButton. http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html – nmagerko Apr 14 '12 at 16:15
  • `Open.setToolTipText (Open);` i make that code, but it show only blue window how can i change colour to yellow? – Luka Toni Apr 14 '12 at 16:27

2 Answers2

3

The message displayed when the user hovers over a JButton is called a tooltip.

You can create one using the code found in the Java tutorial here: http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html

To customize the background of the tooltip, you can do one of two things:

  • Change the Look and Feel
  • Use the following code to change the tooltip alone:

    UIManager.put("ToolTip.background", new ColorUIResource(255, 247, 200)); //#fff7c8
    Border border = BorderFactory.createLineBorder(new Color(76,79,83));    //#4c4f53
    UIManager.put("ToolTip.border", border);
    ToolTipManager.sharedInstance().setDismissDelay(15000); // 15 second delay  
    setToolTipText(message); // Message to display
    

Source: Moon Ocean Oracle Blog

nmagerko
  • 6,586
  • 12
  • 46
  • 71
  • 1
    You do not have to use the `Border` or `.setDismissDelay` if you would not like to; I included it in case you would like to further customize the tooltip. – nmagerko Apr 14 '12 at 16:44
1

The style of the tooltip can be changed in two ways:

  1. It can be changed in the css as follows:

    .tooltip{ -fx-background-color: linear-gradient(#e2ecfe, #99bcfd); }

  2. It can be changed in the code itself as follows:

    final Tooltip t = new Tooltip(advancePlayBaclFlagVo.getDescriptions() + "["+advancePlayBaclFlagVo.getPlantedDateTime()+"]");
    t.setStyle("-fx-background-color: yellow;");

Shantanu Chandra
  • 87
  • 1
  • 1
  • 6