在nimbus上更改DesktopIcon.width [英] Changing DesktopIcon.width on nimbus

查看:89
本文介绍了在nimbus上更改DesktopIcon.width的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改 JInternalFrame 图标化大小,我尝试使用
javax更改L& F默认值。 swing.UIManager.put(DesktopIcon.width,300);
但它不适用于Nimbus,我也尝试更改 DesktopIconUI with

I'm trying to change the JInternalFrame iconifying size, I've tried changing the L&F defaults with javax.swing.UIManager.put("DesktopIcon.width", 300); but it doesn't work on Nimbus, I've also tried changing the DesktopIconUI with

javax.swing.UIManager.put("DesktopIconUI",  javax.swing.plaf.basic.BasicDesktopIconUI.class.getName());

但是一旦我最小化 JInternalFrame 消失,任何消化?

but as soon as I minimize the JInternalFrame it dissapears, any sugestions?

推荐答案

您可以覆盖 getBoundsForIconOf(JInternalFrame) 的方法DefaultDesktopManager

import java.awt.*;
import javax.swing.*;

public class DesktopIconWidthTest {
  public JComponent makeUI() {
    JDesktopPane desktop = new JDesktopPane();
    desktop.setDesktopManager(new DefaultDesktopManager() {
      @Override protected Rectangle getBoundsForIconOf(JInternalFrame f) {
        Rectangle r = super.getBoundsForIconOf(f);
        //System.out.println(r);
        r.width = 300;
        return r;
      }
    });
    desktop.add(createFrame(0));
    desktop.add(createFrame(1));
    return desktop;
  }
  private JInternalFrame createFrame(int i) {
    JInternalFrame f = new JInternalFrame("title" + i, true, true, true, true);
    //TEST:
    //f.setDesktopIcon(new JInternalFrame.JDesktopIcon(f) {
    //  @Override public Dimension getPreferredSize() {
    //    Dimension d = super.getPreferredSize();
    //    d.width = 300;
    //    return d;
    //  }
    //  @Override public Rectangle getBounds() {
    //    Rectangle r = super.getBounds();
    //    r.width = 300;
    //    return r;
    //  }
    //});
    f.setSize(300, 200);
    f.setVisible(true);
    f.setLocation(10 + 60 * i, 10 + 40 * i);
    return f;
  }
  public static void main(String... args) {
    EventQueue.invokeLater(() -> {
      try {
        for (UIManager.LookAndFeelInfo laf: UIManager.getInstalledLookAndFeels()) {
          if ("Nimbus".equals(laf.getName())) {
            UIManager.setLookAndFeel(laf.getClassName());
            break;
          }
        }
        //UIManager.put("DesktopIcon.width", 500);
      } catch (Exception e) {
        e.printStackTrace();
      }
      JFrame f = new JFrame();
      f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      f.getContentPane().add(new DesktopIconWidthTest().makeUI());
      f.setSize(640, 480);
      f.setLocationRelativeTo(null);
      f.setVisible(true);
    });
  }
}







  • 另一种选择是使用 JInternalFrame.JDesktopIcon


    • 更改最小化 JInternalFrame


      • Another option is to use a JInternalFrame.JDesktopIcon:
        • change the Font of the minimized JInternalFrame
        • import java.awt.*;
          import javax.swing.*;
          //import javax.swing.plaf.basic.*;
          import javax.swing.plaf.synth.*;
          
          public class DesktopIconWidthTest2 {
            public JComponent makeUI() {
              JDesktopPane desktop = new JDesktopPane();
              desktop.add(createFrame(0));
              desktop.add(createFrame(1));
              desktop.add(createFrame(2));
              return desktop;
            }
            private JInternalFrame createFrame(int i) {
              JInternalFrame f = new JInternalFrame("title: " + i, true, true, true, true);
              f.setDesktopIcon(new JInternalFrame.JDesktopIcon(f) {
                @Override public Dimension getPreferredSize() {
                  return new Dimension(300, 40);
                }
                @Override public void updateUI() {
                  super.updateUI();
                  if (getUI() instanceof SynthDesktopIconUI) {
                    //NimbusLookAndFeel:
                    setUI(new SynthDesktopIconUI() {
                      @Override
                      protected void installComponents() {
                        super.installComponents();
                        iconPane.setFont(getFont());
                      }
                    });
                  }
                }
                //BasicLookAndFeel work fine
                @Override public Font getFont() {
                  Font font = UIManager.getFont("InternalFrame.titleFont");
                  return font.deriveFont(30f);
                }
              });
          
              //TEST:
              //Container c = ((BasicInternalFrameUI) f.getUI()).getNorthPane();
              //c.setFont(new Font("Monospaced", Font.BOLD, 50));
          
              f.setSize(300, 200);
              f.setVisible(true);
              f.setLocation(10 + 60 * i, 10 + 40 * i);
              return f;
            }
            public static void main(String... args) {
              EventQueue.invokeLater(() -> {
                try {
                  for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(laf.getName())) {
                      UIManager.setLookAndFeel(laf.getClassName());
                      break;
                    }
                  }
                  //TEST:
                  //UIManager.put("DesktopIcon.width", 500);
                  //UIManager.put("InternalFrame.useTaskBar", Boolean.TRUE);
                  //Font font = UIManager.getFont("InternalFrame.titleFont");
                  //UIManager.put("InternalFrame.titleFont", font.deriveFont(60f));
                } catch (Exception e) {
                  e.printStackTrace();
                }
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                f.getContentPane().add(new DesktopIconWidthTest2().makeUI());
                f.setSize(640, 480);
                f.setLocationRelativeTo(null);
                f.setVisible(true);
              });
            }
          }
          

          这篇关于在nimbus上更改DesktopIcon.width的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆