public class TableContextMenu extends MouseAdapter implements AncestorListener
JTable
can be used
although there are additional functionalities for SortingTable
s.
The supported actions can be freely defined as ContextMenuAction
s. There are
several predefined actions available which are used as the default actions for the
context menu.Modifier and Type | Field and Description |
---|---|
static int |
CONTEXT_MENU_IN_HEADER
Activate the context menu in the table header.
|
static int |
CONTEXT_MENU_IN_TABLE
Activate the context menu in the table body.
|
static int |
CONTEXT_MENU_IN_TABLE_AND_PARENT
Activate the context menu in the whole table and its surrounding viewport
(
== ). |
static int |
CONTEXT_MENU_IN_TABLE_HEADER
Activate the context menu in the table header only (
== ). |
static int |
CONTEXT_MENU_IN_VIEWPORT
Activate the context menu in the
JViewport around the table (e.g. |
static int |
CONTEXT_MENU_IN_WHOLE_TABLE
Activate the context menu in the table header and the table body (
== ). |
static ContextMenuAction |
SEPARATOR
Separator entry for the context menu.
|
Constructor and Description |
---|
TableContextMenu(JTable pTable)
Constructor to install this context menu in a table.
|
TableContextMenu(JTable pTable,
int pMode)
Constructor to install this context menu in a table.
|
TableContextMenu(JTable pTable,
int pMode,
ContextMenuAction[] pActions)
Constructor to install this context menu in a table.
|
Modifier and Type | Method and Description |
---|---|
void |
ancestorAdded(AncestorEvent pEvent)
Check if the parent of our table has changed.
|
void |
ancestorMoved(AncestorEvent pEvent)
We are not interested in this event.
|
void |
ancestorRemoved(AncestorEvent pEvent)
Check if the parent of our table has changed.
|
void |
dispose()
Disconnect the context menu from its table.
|
int |
getMode()
Return the mode as a bitflag consisting of
CONTEXT_MENU_IN_TABLE , CONTEXT_MENU_IN_HEADER and CONTEXT_MENU_IN_VIEWPORT . |
void |
mousePressed(MouseEvent pEvent)
React on mouse pressed events.
|
void |
mouseReleased(MouseEvent pEvent)
React on mouse released events.
|
void |
setMode(int pMode)
Set the mode as a bitflag consisting of
CONTEXT_MENU_IN_TABLE , CONTEXT_MENU_IN_HEADER and CONTEXT_MENU_IN_VIEWPORT . |
mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseWheelMoved
public static final int CONTEXT_MENU_IN_TABLE
public static final int CONTEXT_MENU_IN_HEADER
public static final int CONTEXT_MENU_IN_VIEWPORT
JViewport
around the table (e.g. from a JScrollPane
).public static final int CONTEXT_MENU_IN_TABLE_HEADER
== CONTEXT_MENU_IN_HEADER
).
This constant is only provided for convenience.public static final int CONTEXT_MENU_IN_WHOLE_TABLE
== CONTEXT_MENU_IN_TABLE
| CONTEXT_MENU_IN_HEADER
).
This constant is only provided for convenience.public static final int CONTEXT_MENU_IN_TABLE_AND_PARENT
== CONTEXT_MENU_IN_TABLE
| CONTEXT_MENU_IN_HEADER
| CONTEXT_MENU_IN_VIEWPORT
).
This constant is only provided for convenience.public static final ContextMenuAction SEPARATOR
public TableContextMenu(JTable pTable)
== CONTEXT_MENU_IN_TABLE
| CONTEXT_MENU_IN_HEADER
| CONTEXT_MENU_IN_VIEWPORT
.
The actions are assumed to be the default actions.pTable
- table this context menu works on (must not be null
)public TableContextMenu(JTable pTable, int pMode)
pTable
- table this context menu works on (must not be null
)pMode
- a bitflag consisting of CONTEXT_MENU_IN_TABLE
, CONTEXT_MENU_IN_HEADER
and/or CONTEXT_MENU_IN_VIEWPORT
public TableContextMenu(JTable pTable, int pMode, ContextMenuAction[] pActions)
pTable
- table this context menu works on (must not be null
)pMode
- a bitflag consisting of CONTEXT_MENU_IN_TABLE
, CONTEXT_MENU_IN_HEADER
and/or CONTEXT_MENU_IN_VIEWPORT
pActions
- actions to include in the context menu (must not be null
)public void dispose()
public int getMode()
CONTEXT_MENU_IN_TABLE
, CONTEXT_MENU_IN_HEADER
and CONTEXT_MENU_IN_VIEWPORT
.public void setMode(int pMode)
CONTEXT_MENU_IN_TABLE
, CONTEXT_MENU_IN_HEADER
and CONTEXT_MENU_IN_VIEWPORT
.pMode
- new modepublic void mousePressed(MouseEvent pEvent)
mousePressed
in interface MouseListener
mousePressed
in class MouseAdapter
public void mouseReleased(MouseEvent pEvent)
mouseReleased
in interface MouseListener
mouseReleased
in class MouseAdapter
public void ancestorAdded(AncestorEvent pEvent)
ancestorAdded
in interface AncestorListener
public void ancestorRemoved(AncestorEvent pEvent)
ancestorRemoved
in interface AncestorListener
public void ancestorMoved(AncestorEvent pEvent)
ancestorMoved
in interface AncestorListener
Copyright © 2017 Jürgen Zeller (privat). All rights reserved.