39 |
package javax.swing; |
package javax.swing; |
40 |
|
|
41 |
import java.awt.Component; |
import java.awt.Component; |
42 |
|
import java.awt.FlowLayout; |
43 |
import java.awt.Point; |
import java.awt.Point; |
44 |
|
|
45 |
|
|
225 |
* The panel that holds the content. |
* The panel that holds the content. |
226 |
*/ |
*/ |
227 |
private JPanel panel; |
private JPanel panel; |
228 |
|
|
229 |
|
/** |
230 |
|
* The layered pane of the owner. |
231 |
|
*/ |
232 |
|
private JLayeredPane layeredPane; |
233 |
|
|
234 |
/** |
/** |
235 |
* Constructs a new <code>LightweightPopup</code> given its owner, |
* Constructs a new <code>LightweightPopup</code> given its owner, |
236 |
* contents and the screen position where the popup |
* contents and the screen position where the popup |
258 |
this.contents = contents; |
this.contents = contents; |
259 |
this.x = x; |
this.x = x; |
260 |
this.y = y; |
this.y = y; |
261 |
|
|
262 |
|
JRootPane rootPane = SwingUtilities.getRootPane(owner); |
263 |
|
JLayeredPane layeredPane = rootPane.getLayeredPane(); |
264 |
|
this.layeredPane = layeredPane; |
265 |
} |
} |
266 |
|
|
267 |
/** |
/** |
270 |
*/ |
*/ |
271 |
public void show() |
public void show() |
272 |
{ |
{ |
|
JRootPane rootPane = SwingUtilities.getRootPane(owner); |
|
|
JLayeredPane layeredPane = rootPane.getLayeredPane(); |
|
273 |
// We insert a JPanel between the layered pane and the contents so we |
// We insert a JPanel between the layered pane and the contents so we |
274 |
// can fiddle with the setLocation() method without disturbing a |
// can fiddle with the setLocation() method without disturbing a |
275 |
// JPopupMenu (which overrides setLocation in an unusual manner). |
// JPopupMenu (which overrides setLocation in an unusual manner). |
276 |
if (panel == null) |
if (panel == null) |
277 |
{ |
{ |
278 |
panel = new JPanel(); |
panel = new JPanel(); |
279 |
panel.setLayout(null); |
panel.setLayout(new FlowLayout(0, 0, 0)); |
280 |
} |
} |
281 |
|
|
282 |
panel.add(contents); |
panel.add(contents); |
283 |
panel.setSize(contents.getSize()); |
panel.setSize(contents.getSize()); |
284 |
Point layeredPaneLoc = layeredPane.getLocationOnScreen(); |
Point layeredPaneLoc = layeredPane.getLocationOnScreen(); |
291 |
*/ |
*/ |
292 |
public void hide() |
public void hide() |
293 |
{ |
{ |
|
JRootPane rootPane = SwingUtilities.getRootPane(owner); |
|
|
JLayeredPane layeredPane = rootPane.getLayeredPane(); |
|
294 |
layeredPane.remove(panel); |
layeredPane.remove(panel); |
295 |
} |
} |
296 |
} |
} |