修改一些问题

This commit is contained in:
wenli 2024-07-29 08:59:57 +08:00
parent cf5b085243
commit 024cb688ae
3 changed files with 32 additions and 23 deletions

View File

@ -90,7 +90,7 @@ public class IconLoader {
* @return {@link FlatSVGIcon} * @return {@link FlatSVGIcon}
*/ */
public static FlatSVGIcon getSvgIcon(String path, int w, int h) { public static FlatSVGIcon getSvgIcon(String path, int w, int h) {
if (StrUtil.isBlank(path)|| !FileUtil.isFile(path)) { if (StrUtil.isBlank(path)|| IconLoader.class.getResourceAsStream("/"+path) == null) {
path = "icons/item.svg"; path = "icons/item.svg";
} }
FlatSVGIcon flatSVGIcon = new FlatSVGIcon(path, w, h); FlatSVGIcon flatSVGIcon = new FlatSVGIcon(path, w, h);

View File

@ -59,7 +59,7 @@ public class MainFrame extends JFrame {
private JButton themeBut; private JButton themeBut;
private JButton refreshBut; private JButton refreshBut;
private JButton noticeBut; private JButton noticeBut;
private JPopupMenu themePopupMenu;
private MainFrame() { private MainFrame() {
MainPrefs.init(PREFS_ROOT_PATH); MainPrefs.init(PREFS_ROOT_PATH);
@ -282,7 +282,15 @@ public class MainFrame extends JFrame {
public JMenuBar getTitleMenuBar() { public JMenuBar getTitleMenuBar() {
if (titleMenuBar == null) { if (titleMenuBar == null) {
titleMenuBar = new JMenuBar(); titleMenuBar = new JMenuBar() {
@Override
public void updateUI() {
super.updateUI();
if (themePopupMenu != null) {
SwingUtilities.updateComponentTreeUI(themePopupMenu);
}
}
};
// left // left
titleMenuBar.add(getTitleLabel()); titleMenuBar.add(getTitleLabel());
titleMenuBar.add(Box.createGlue()); titleMenuBar.add(Box.createGlue());
@ -297,7 +305,7 @@ public class MainFrame extends JFrame {
public JButton getNoticeBut() { public JButton getNoticeBut() {
if (noticeBut == null) { if (noticeBut == null) {
noticeBut = new JButton(); noticeBut = new JButton();
noticeBut.setIcon( new FlatSVGIcon("icons/bell.svg", 25, 25)); noticeBut.setIcon(new FlatSVGIcon("icons/bell.svg", 25, 25));
noticeBut.putClientProperty("JButton.buttonType", "toolBarButton"); noticeBut.putClientProperty("JButton.buttonType", "toolBarButton");
noticeBut.setFocusable(false); noticeBut.setFocusable(false);
noticeBut.addActionListener(e -> { noticeBut.addActionListener(e -> {
@ -305,7 +313,7 @@ public class MainFrame extends JFrame {
MyNotifyMessagePane myNotifyMessagePane; MyNotifyMessagePane myNotifyMessagePane;
if (tabIndex == -1) { if (tabIndex == -1) {
myNotifyMessagePane = new MyNotifyMessagePane(); myNotifyMessagePane = new MyNotifyMessagePane();
MainFrame.getInstance().getTabbedPane().addTab("我的消息",new FlatSVGIcon("icons/bell.svg", 25, 25), myNotifyMessagePane); MainFrame.getInstance().getTabbedPane().addTab("我的消息", new FlatSVGIcon("icons/bell.svg", 25, 25), myNotifyMessagePane);
} else { } else {
myNotifyMessagePane = (MyNotifyMessagePane) MainFrame.getInstance().getTabbedPane().getComponentAt(tabIndex); myNotifyMessagePane = (MyNotifyMessagePane) MainFrame.getInstance().getTabbedPane().getComponentAt(tabIndex);
} }
@ -400,25 +408,28 @@ public class MainFrame extends JFrame {
*/ */
private void showPopupSkinButtonActionPerformed(ActionEvent e) { private void showPopupSkinButtonActionPerformed(ActionEvent e) {
Component invoker = (Component) e.getSource(); Component invoker = (Component) e.getSource();
JPopupMenu themePopupMenu = new JPopupMenu(); if (themePopupMenu == null) {
ButtonGroup group = new ButtonGroup(); themePopupMenu = new JPopupMenu();
ButtonGroup group = new ButtonGroup();
JCheckBoxMenuItem lighterMenuItem = new JCheckBoxMenuItem("白色"); JCheckBoxMenuItem lighterMenuItem = new JCheckBoxMenuItem("白色");
group.add(lighterMenuItem); group.add(lighterMenuItem);
themePopupMenu.add(lighterMenuItem); themePopupMenu.add(lighterMenuItem);
lighterMenuItem.addActionListener(e1 -> theme("白色")); lighterMenuItem.addActionListener(e1 -> theme("白色"));
JCheckBoxMenuItem darkMenuItem = new JCheckBoxMenuItem("深色"); JCheckBoxMenuItem darkMenuItem = new JCheckBoxMenuItem("深色");
darkMenuItem.addActionListener(e1 -> theme("深色")); darkMenuItem.addActionListener(e1 -> theme("深色"));
themePopupMenu.add(darkMenuItem); themePopupMenu.add(darkMenuItem);
group.add(darkMenuItem); group.add(darkMenuItem);
JCheckBoxMenuItem glazzedMenuItem = new JCheckBoxMenuItem("玻璃"); JCheckBoxMenuItem glazzedMenuItem = new JCheckBoxMenuItem("玻璃");
glazzedMenuItem.addActionListener(e1 -> theme("玻璃")); glazzedMenuItem.addActionListener(e1 -> theme("玻璃"));
themePopupMenu.add(glazzedMenuItem); themePopupMenu.add(glazzedMenuItem);
group.add(glazzedMenuItem); group.add(glazzedMenuItem);
}
themePopupMenu.show(invoker, 0, invoker.getHeight()); themePopupMenu.show(invoker, 0, invoker.getHeight());

View File

@ -72,11 +72,9 @@ public class SidePane extends WPanel {
}else if (StrUtil.contains(icon,":")){ }else if (StrUtil.contains(icon,":")){
icon="icons/menu/"+icon.split(":")[1]+".svg"; icon="icons/menu/"+icon.split(":")[1]+".svg";
} }
FlatSVGIcon svgIcon = new FlatSVGIcon(icon, 25, 25); FlatSVGIcon svgIcon = IconLoader.getSvgIcon(icon,25,25);
svgIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> {
return component.getForeground();
}));
((JLabel) component).setIcon(svgIcon); ((JLabel) component).setIcon(svgIcon);
} }