diff --git a/src/dorkbox/systemTray/swing/AdjustedJMenu.java b/src/dorkbox/systemTray/swing/AdjustedJMenu.java new file mode 100644 index 0000000..74767e0 --- /dev/null +++ b/src/dorkbox/systemTray/swing/AdjustedJMenu.java @@ -0,0 +1,40 @@ +/* + * Copyright 2016 dorkbox, llc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package dorkbox.systemTray.swing; + +import java.awt.Insets; + +import javax.swing.JMenu; +import javax.swing.JPopupMenu; +import javax.swing.border.EmptyBorder; + +class AdjustedJMenu extends JMenu { + @Override + public + Insets getMargin() { + Insets margin = super.getMargin(); + if (margin != null) { + margin.set(2, -2, 2, 4); + + // makes sure the popup menu is created. + JPopupMenu popupMenu = getPopupMenu(); + // now adjust the border of it + popupMenu.setBorder(new EmptyBorder(1, 1, 1, 1)); + } + + return margin; + } +} diff --git a/src/dorkbox/systemTray/swing/AdjustedJMenuItem.java b/src/dorkbox/systemTray/swing/AdjustedJMenuItem.java index b0cbed6..2d41694 100644 --- a/src/dorkbox/systemTray/swing/AdjustedJMenuItem.java +++ b/src/dorkbox/systemTray/swing/AdjustedJMenuItem.java @@ -20,6 +20,10 @@ import java.awt.Insets; import javax.swing.JMenuItem; class AdjustedJMenuItem extends JMenuItem { + AdjustedJMenuItem() { + super(); + } + @Override public Insets getMargin() { diff --git a/src/dorkbox/systemTray/swing/SwingMenu.java b/src/dorkbox/systemTray/swing/SwingMenu.java index 3b38951..9b88568 100644 --- a/src/dorkbox/systemTray/swing/SwingMenu.java +++ b/src/dorkbox/systemTray/swing/SwingMenu.java @@ -22,7 +22,6 @@ import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JComponent; -import javax.swing.JMenu; import javax.swing.JMenuItem; import dorkbox.systemTray.Menu; @@ -56,10 +55,12 @@ class SwingMenu extends Menu implements MenuEntry { @Override public void run() { - _native = new JMenu(); - if (parent != null) { + _native = new AdjustedJMenu(); ((SwingMenu) parent)._native.add(_native); + } else { + // when we are the system tray + _native = new SwingSystemTrayMenuPopup(); } } });