Added ability for swing menu's to change size in scale with the display.

This commit is contained in:
nathan 2017-01-25 21:49:55 +01:00
parent bc5871d920
commit cd51b756dd
3 changed files with 26 additions and 1 deletions

View File

@ -15,14 +15,27 @@
*/
package dorkbox.systemTray.swingUI;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import javax.swing.border.EmptyBorder;
import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.util.ImageUtils;
class AdjustedJMenu extends JMenu {
// get the scale (and multiply it to our font size) to get the new font size
private static int scale = ImageUtils.ENTRY_SIZE / SystemTray.DEFAULT_MENU_SIZE;
AdjustedJMenu() {
super();
Font font = getFont();
int size = font.getSize();
size = size * scale;
setFont(new Font(font.getName(), font.getStyle(), size));
}
@Override

View File

@ -15,13 +15,25 @@
*/
package dorkbox.systemTray.swingUI;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.JMenuItem;
import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.util.ImageUtils;
class AdjustedJMenuItem extends JMenuItem {
// get the scale (and multiply it to our font size) to get the new font size
private static int scale = ImageUtils.ENTRY_SIZE / SystemTray.DEFAULT_MENU_SIZE;
AdjustedJMenuItem() {
super();
Font font = getFont();
int size = font.getSize();
size = size * scale;
setFont(new Font(font.getName(), font.getStyle(), size));
}
@Override

View File

@ -138,7 +138,7 @@ class ImageUtils {
// casting around for rounding/math stuff
// *2 because we want a 2x scale to be 64, not 32.
trayScalingFactor = (int) (((double) dpiX) / ((double) 96)) * 2;
// we don't want to scale the size of the menu, because java/swing takes care of scaling for us.
menuScalingFactor = trayScalingFactor;
}