Force HeavyWeight Tooltip with JPanel Form

I am working on a custom form application and have some problems with my button tips. I isolated the problem in a simple example that illustrates exactly my situation.

You can see that the tooltip of the middle button is well displayed because it is larger than the root panel, but the one on the left button does not work and is hidden by my custom form.

Here is my example:

import java.awt.Point; import java.awt.Polygon; import java.awt.Shape; import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.ToolTipManager; public class ButtonDemo extends JPanel { protected JButton b1, b2, b3; public ButtonDemo() { b1 = new JButton("Disable middle button"); b1.setVerticalTextPosition(AbstractButton.CENTER); b1.setHorizontalTextPosition(AbstractButton.LEADING); b2 = new JButton("Middle button"); b2.setVerticalTextPosition(AbstractButton.BOTTOM); b2.setHorizontalTextPosition(AbstractButton.CENTER); b3 = new JButton("Enable middle button"); b3.setEnabled(false); b1.setToolTipText("Click this button to disable the middle button."); b2.setToolTipText("This middle button does nothing when you click it. This middle button does nothing when you click it. This middle button does nothing when you click it."); b3.setToolTipText("Click this button to enable the middle button."); add(b1); add(b2); add(b3); } private static void createAndShowGUI() { JFrame frame = new JFrame("ButtonDemo"); frame.setUndecorated(true); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. ButtonDemo newContentPane = new ButtonDemo(); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setSize(1024, 768); frame.setVisible(true); frame.setLocation(0, 0); // Shape final Point[] points = new Point[]{ // new Point(0, 0), // new Point(0, frame.getHeight()), // new Point(frame.getWidth() - 400, frame.getHeight()), // new Point(frame.getWidth() - 400, 25), // new Point(frame.getWidth(), 25), // new Point(frame.getWidth(), 0), // new Point(0, 0)}; int[] xpoints = new int[points.length]; int[] ypoints = new int[points.length]; for (int i = 0; i < points.length; i++) { xpoints[i] = (int) points[i].getX(); ypoints[i] = (int) points[i].getY(); } Shape formeFenetre = new Polygon(xpoints, ypoints, points.length); frame.setShape(formeFenetre); } public static void main(final String[] args) { ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { createAndShowGUI(); } }); } } 

I thought: "ToolTipManager.sharedInstance (). SetLightWeightPopupEnabled (false);" was exactly what I was looking for, but not working very well with my JRE. By the way, I am using Java 1.7.0_09, but should work with any JRE in 1.7.

Hope someone knows what to do! Thank you for reading.

+4
source share

Source: https://habr.com/ru/post/1486642/


All Articles