public class PopupManager extends Object
Modifier and Type | Class and Description |
---|---|
static class |
PopupManager.HorizontalBounds
Horizontal bounds of popup panel specification
|
static class |
PopupManager.Placement
Placement of popup panel specification
|
Modifier and Type | Field and Description |
---|---|
static PopupManager.Placement |
Above
Place popup always above cursor
|
static PopupManager.Placement |
AbovePreferred
Place popup above cursor.
|
static PopupManager.Placement |
Below
Place popup always below cursor
|
static PopupManager.Placement |
BelowPreferred
Place popup below cursor.
|
static PopupManager.Placement |
FixedPoint
Place the popup on a fixed point of the view, measured from top-left corner
|
static PopupManager.Placement |
Largest
Place popup to larger area.
|
static PopupManager.HorizontalBounds |
ScrollBarBounds
Place popup inside the whole scrollbar
|
static PopupManager.HorizontalBounds |
ViewPortBounds
Place popup inside the scrollbar's viewport
|
Constructor and Description |
---|
PopupManager(JTextComponent textComponent)
Creates a new instance of PopupManager
|
Modifier and Type | Method and Description |
---|---|
protected static Rectangle |
computeBounds(JComponent popup,
int viewWidth,
int viewHeight,
Rectangle cursorBounds,
PopupManager.Placement placement) |
protected static Rectangle |
computeBounds(JComponent popup,
int viewWidth,
int viewHeight,
Rectangle cursorBounds,
PopupManager.Placement originalPlacement,
PopupManager.HorizontalBounds horizontalBounds)
Computes a best-fit bounds of popup panel
according to available space in the underlying view
(visible part of the pane).
|
protected static Rectangle |
computeBounds(JComponent popup,
JComponent view,
Rectangle cursorBounds,
PopupManager.Placement placement) |
protected static Rectangle |
computeBounds(JComponent popup,
JComponent view,
Rectangle cursorBounds,
PopupManager.Placement placement,
PopupManager.HorizontalBounds horizontalBounds)
Variation of the method for computing the bounds
for the concrete view component.
|
JComponent |
get()
Returns installed popup panel component
|
void |
install(JComponent popup)
Install popup component to textComponent root pane
based on caret coordinates with the
Largest placement. |
void |
install(JComponent popup,
Rectangle cursorBounds,
PopupManager.Placement placement) |
void |
install(JComponent popup,
Rectangle cursorBounds,
PopupManager.Placement placement,
PopupManager.HorizontalBounds horizontalBounds) |
void |
install(JComponent popup,
Rectangle cursorBounds,
PopupManager.Placement placement,
PopupManager.HorizontalBounds horizontalBounds,
int horizontalAdjustment,
int verticalAdjustment) |
void |
uninstall(JComponent popup)
Removes popup component from textComponent root pane
|
public static final PopupManager.Placement Above
public static final PopupManager.Placement Below
public static final PopupManager.Placement Largest
public static final PopupManager.Placement AbovePreferred
public static final PopupManager.Placement BelowPreferred
public static final PopupManager.Placement FixedPoint
public static final PopupManager.HorizontalBounds ViewPortBounds
public static final PopupManager.HorizontalBounds ScrollBarBounds
public PopupManager(JTextComponent textComponent)
public void install(JComponent popup)
Largest
placement.
Note: Make sure the component is properly uninstalled later,
if it is not necessary. See issue #35325 for details.popup
- popup component to be installed into
root pane of the text component.public void uninstall(JComponent popup)
popup
- popup component to be removed from
root pane of the text component.public void install(JComponent popup, Rectangle cursorBounds, PopupManager.Placement placement, PopupManager.HorizontalBounds horizontalBounds, int horizontalAdjustment, int verticalAdjustment)
public void install(JComponent popup, Rectangle cursorBounds, PopupManager.Placement placement, PopupManager.HorizontalBounds horizontalBounds)
public void install(JComponent popup, Rectangle cursorBounds, PopupManager.Placement placement)
public JComponent get()
protected static Rectangle computeBounds(JComponent popup, JComponent view, Rectangle cursorBounds, PopupManager.Placement placement, PopupManager.HorizontalBounds horizontalBounds)
popup
- popup panel to be displayedview
- component over which the popup is displayed.cursorBounds
- the bounds of the caret or mouse cursor
relative to the upper-left corner of the visible view.placement
- where to place the popup panel according to
the cursor position.null
if there is no place to display popup.protected static Rectangle computeBounds(JComponent popup, JComponent view, Rectangle cursorBounds, PopupManager.Placement placement)
protected static Rectangle computeBounds(JComponent popup, int viewWidth, int viewHeight, Rectangle cursorBounds, PopupManager.Placement originalPlacement, PopupManager.HorizontalBounds horizontalBounds)
popup.putClientProperty(Placement.class, actual-placement)
.
The actual placement is Above
if the original placement was Above
.
Or if the original placement was AbovePreferred
or Largest
and there is more space above the cursor than below it.
Below
if the original placement was Below
.
Or if the original placement was BelowPreferred
or Largest
and there is more space below the cursor than above it.
AbovePreferred
if the original placement
was AbovePreferred
and there is less space above the cursor than below it.
BelowPreferred
if the original placement
was BelowPreferred
and there is less space below the cursor than above it.
Once the placement client property is set
the popup.setSize()
is called with the size of the area
above/below the cursor (indicated by the placement).
The popup responds by updating its size to the equal or smaller
size. If it cannot physically fit into the requested area
it can call
putClientProperty(Placement.class, null)
on itself to indicate that it cannot fit. The method scans
the content of the client property upon return from
popup.setSize()
and if it finds null there it returns
null bounds in that case. The only exception is
if the placement was either AbovePreferred
or BelowPreferred
. In that case the method
gives it one more try
by attempting to fit the popup into (bigger) complementary
Below
and Above
areas (respectively).
The popup either fits into these (bigger) areas or it again responds
by returning null
in the client property in which case
the method finally gives up and returns null bounds.
popup
- popup panel to be displayedviewWidth
- width of the visible view area.viewHeight
- height of the visible view area.cursorBounds
- the bounds of the caret or mouse cursor
relative to the upper-left corner of the visible vieworiginalPlacement
- where to place the popup panel according to
the cursor positionnull
if there is no place to display popup.protected static Rectangle computeBounds(JComponent popup, int viewWidth, int viewHeight, Rectangle cursorBounds, PopupManager.Placement placement)