Code polish, fixed newly craeted JPopupMenu border + margin info.

This commit is contained in:
nathan 2016-09-29 03:23:33 +02:00
parent b354daab68
commit 05231587d2
3 changed files with 48 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -20,6 +20,10 @@ import java.awt.Insets;
import javax.swing.JMenuItem;
class AdjustedJMenuItem extends JMenuItem {
AdjustedJMenuItem() {
super();
}
@Override
public
Insets getMargin() {

View File

@ -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();
}
}
});