Force separators to be the same width as the JPopupMenu. This is because the MenuLayout make separators invisible contrary to the default JPopupMenu layout manager. @param aFlag true if the popupmenu is visible
(boolean aFlag)
| 43 | * @param aFlag true if the popupmenu is visible |
| 44 | */ |
| 45 | @Override |
| 46 | public void setVisible(boolean aFlag) { |
| 47 | super.setVisible(aFlag); |
| 48 | if (!aFlag) { return; } |
| 49 | MenuLayout layout = (MenuLayout) getLayout(); |
| 50 | for (int i = 0; i < getComponents().length; i++) { |
| 51 | Component component = getComponents()[i]; |
| 52 | if (component instanceof JSeparator) { |
| 53 | JSeparator separator = (JSeparator) component; |
| 54 | int column = layout.getColumnForComponentIndex(i); |
| 55 | int preferredWidth = layout.getPreferredWidthForColumn(column); |
| 56 | // use the popupmenu width to set the separators width |
| 57 | separator.setPreferredSize(new Dimension( |
| 58 | preferredWidth, separator.getHeight())); |
| 59 | } |
| 60 | } |
| 61 | revalidate(); |
| 62 | } |
| 63 | } |
no test coverage detected