我创建了一个表,在这个表中,某些行可以使用组合框进行编辑。我希望这个组合框能够通过右键单击而不是左键单击打开。我尝试了几件事,但我认为这是我最接近的方法:
java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:2062)
at java.awt.Component.getLocationOnScreen(Component.java:2036)
at javax.swing.JPopupMenu.show(JPopupMenu.java:948)
at javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:209)
at javax.swing.plaf.basic.BasicComboBoxUI.setPopupVisible(BasicComboBoxUI.java:877)
at javax.swing.JComboBox.setPopupVisible(JComboBox.java:816)
at javax.swing.JComboBox.showPopup(JComboBox.java:801)
at org.zaproxy.zap.extension.authorisationChecker.view.AuthorisationCheckerStatusPanel$1.mouseClicked(AuthorisationCheckerStatusPanel.java:154)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6536)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
但是,它给了我以下错误:
@Search nvarchar(50) = ' '
AS
BEGIN
SET NOCOUNT ON;
exec ('select
TRIM (vhitno) AS Item,
TRIM (mmitds) AS Description,
TRIM (SUBSTRING (vhitno,12,4)) AS Size,
vhalqt AS Available
from m3fdbtest.oagrln
left outer join
m3fdbtest.mdeohe on vhcono=uwcono and vhcuno=uwcuno and vhagno=uwagno and vhitno=uwobv1
left outer join
m3fdbtest.mitmas ON vhcono = mmcono AND vhitno = mmitno
where
uwcono=1
and
uwcuno=''JBHE0001''
and
uwagst=''20''
and
vhitno LIKE ''%'' || ? || ''%'' '
, @Search ) at M3_TEST_ODBC
由box.showPopup();
引起我不明白这个错误,因为editCellAt确实显示了组合框。它确实(显然^^)没有打开组合框。
谢谢!
答案 0 :(得分:1)
您需要访问用作单元格编辑器的组合框。
基本代码是:
int row = table.rowAtPoint(e.getPoint());
int column = table.columnAtPoint(e.getPoint());
table.changeSelection(row, column, false, false);
table.editCellAt(row, column);
Component c = table.getEditorComponent();
if (c instanceof JComboBox)
{
JComboBox comboBox = (JComboBox)c;
comboBox.showPopup();
}