1
A
回答
0
您可能能夠覆蓋的DefaultDesktopManager
的iconifyFrame(...)
方法和JInternalFrame.JDesktopIcon
getPreferredSize()
方法來設置DesktopIcon
大小。
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
謝謝!這正是我需要的。 –
相關問題
- 1. 設置表格的最小尺寸
- 2. 設置QBoxLayout最大尺寸?
- 3. 在Java中的JInternalFrame中設置JTabbedPane上的JPanel的尺寸
- 4. 根據內容的大小設置幀的最小尺寸
- 5. gtk最小尺寸
- 6. 使用WINAPI設置窗口的最小和最大尺寸
- 7. 設置窗口的最小和最大尺寸
- 8. 如何在Android中爲ImageView設置最小和最大尺寸
- 9. GGplot2的最小尺寸geom_text()
- 10. 設置JPanel的最大尺寸內BorderLayout.CENTER
- 11. 如何設置JFrame的最大尺寸?
- 12. 設置JFrame的最大尺寸
- 13. JAVA設置JFrame的最大尺寸
- 14. 設置一個JDialog的最大尺寸?
- 15. UIScroll視圖設置初始圖像尺寸小於全尺寸
- 16. 設置打印紙張尺寸的最小高度?
- 17. Qt 5.3.2 /設置QToolBox項目的最小尺寸
- 18. HighCharts漏斗 - 設置每個部分的最小尺寸
- 19. 如何設置Vim的最小分割尺寸
- 20. 在codenameone中設置組件的最小尺寸
- 21. 在Java中設置地圖的最小尺寸
- 22. 設置SplitterContainer面板的最小允許尺寸
- 23. 如何設置背景尺寸的最小寬度
- 24. 如何設置一個xulrunner主窗口的最小尺寸?
- 25. 如何在fxml中設置容器的最小尺寸
- 26. 如何在wxRuby中設置窗口的最小尺寸
- 27. Java(Eclipse)WindowBuilder設置最大尺寸
- 28. 將deque max_size設置爲最大尺寸
- 29. 設置圖像最大尺寸
- 30. 按鈕:最小尺寸
在某些外觀,可以將鼠標懸停看名字。 – trashgod