From 28d2b300f1d5a472680e50ebe6ca7e4d5ec67df3 Mon Sep 17 00:00:00 2001 From: Tergel TSAGAAN Date: Thu, 7 Jan 2021 14:38:53 +0100 Subject: [PATCH] fix popup doesn't appear when left click added cell selection when displaying popup --- src/main/java/GUI/Agenda/Agenda.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/GUI/Agenda/Agenda.java b/src/main/java/GUI/Agenda/Agenda.java index 47b80ec..1c5b770 100644 --- a/src/main/java/GUI/Agenda/Agenda.java +++ b/src/main/java/GUI/Agenda/Agenda.java @@ -1,6 +1,7 @@ package GUI.Agenda; -import DB.*; +import DB.Competition; +import DB.Projection; import GUI.ProjectionHandler; import GUI.Types.CompetType; import GUI.Types.ProjectionType; @@ -92,6 +93,20 @@ public class Agenda extends JPanel { table.setRowHeight(100); Agenda tmp = this; table.addMouseListener(new MouseInputAdapter() { + @Override + public void mouseReleased(MouseEvent mouseEvent) { + if (mouseEvent.isPopupTrigger()) { + int row = table.rowAtPoint(mouseEvent.getPoint()); + int column = table.getTableHeader().columnAtPoint(mouseEvent.getPoint()); + table.changeSelection(row, column, false, false); + Object currentCellValue = table.getValueAt(row, column); + Projection projection = null; + if (currentCellValue.getClass() == Projection.class) + projection = (Projection) currentCellValue; + PopUpProjection popUpProjection = new PopUpProjection(projection, tmp); + popUpProjection.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); + } + } @Override public void mousePressed(MouseEvent mouseEvent) { @@ -105,8 +120,7 @@ public class Agenda extends JPanel { } else { openDialog(ProjectionType.EDIT, projection); } - } - else if (mouseEvent.isPopupTrigger()) { + } else if (mouseEvent.isPopupTrigger()) { PopUpProjection popUpProjection = new PopUpProjection(projection, tmp); popUpProjection.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); }