2017-08-02 204 views
1

我有它的一些JInternalframe窗戶JDesktopPane所看到如下圖所示:設置JInternalFrame的最小尺寸

https://i.stack.imgur.com/xCReF.png

當我儘量減少他們,他們沒有表現出自己的全名。有沒有辦法讓它充分顯示?

+0

在某些外觀,可以將鼠標懸停看名字。 – trashgod

回答

0

您可能能夠覆蓋的DefaultDesktopManagericonifyFrame(...)方法和JInternalFrame.JDesktopIcongetPreferredSize()方法來設置DesktopIcon大小。

screenshot

import java.awt.*; 
import javax.swing.*; 
//https://stackoverflow.com/questions/35287367/changing-desktopicon-width-on-nimbus 
public class DesktopIconWidthTest2 { 
    public JComponent makeUI() { 
    JDesktopPane desktop = new JDesktopPane(); 
    desktop.setDesktopManager(new DefaultDesktopManager() { 
     @Override public void iconifyFrame(JInternalFrame f) { 
     Rectangle r = this.getBoundsForIconOf(f); 
     r.width = f.getDesktopIcon().getPreferredSize().width; 
     f.getDesktopIcon().setBounds(r); 
     super.iconifyFrame(f); 
     } 
    }); 
    desktop.add(createFrame("looooooooooooong title #", 1)); 
    desktop.add(createFrame("#", 0)); 
    return desktop; 
    } 
    private JInternalFrame createFrame(String t, int i) { 
    JInternalFrame f = new JInternalFrame(t + i, true, true, true, true); 
    f.setDesktopIcon(new JInternalFrame.JDesktopIcon(f) { 
     @Override public Dimension getPreferredSize() { 
     Dimension d = f.getMinimumSize(); 
     String title = f.getTitle(); 
     FontMetrics fm = getFontMetrics(getFont()); 
     //Magic Number 16: margin? 
     d.width += SwingUtilities.computeStringWidth(fm, title) - 16; 
     return d; 
     } 
    }); 
    f.setSize(200, 100); 
    f.setVisible(true); 
    f.setLocation(5 + 40 * i, 5 + 50 * i); 
    return f; 
    } 
    public static void main(String[] args) { 
    EventQueue.invokeLater(() -> { 
     try { 
     UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); 
     // MetalLookAndFeel: UIManager.put("DesktopIcon.width", 500); 
     } catch (Exception e) { 
     e.printStackTrace(); 
     } 
     JFrame f = new JFrame(); 
     f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
     f.getContentPane().add(new DesktopIconWidthTest2().makeUI()); 
     f.setSize(320, 240); 
     f.setLocationRelativeTo(null); 
     f.setVisible(true); 
    }); 
    } 
} 
+0

謝謝!這正是我需要的。 –