65
66 public static ComponentUI createUI(JComponent x) {
67 return new MotifPopupMenuUI();
68 }
69
70 /* This has to deal with the fact that the title may be wider than
71 the widest child component.
72 */
73 public Dimension getPreferredSize(JComponent c) {
74 LayoutManager layout = c.getLayout();
75 Dimension d = layout.preferredLayoutSize(c);
76 String title = ((JPopupMenu)c).getLabel();
77 if (titleFont == null) {
78 UIDefaults table = UIManager.getLookAndFeelDefaults();
79 titleFont = table.getFont("PopupMenu.font");
80 }
81 FontMetrics fm = c.getFontMetrics(titleFont);
82 int stringWidth = 0;
83
84 if (title!=null) {
85 stringWidth += SwingUtilities2.stringWidth(c, fm, title);
86 }
87
88 if (d.width < stringWidth) {
89 d.width = stringWidth + 8;
90 Insets i = c.getInsets();
91 if (i!=null) {
92 d.width += i.left + i.right;
93 }
94 if (border != null) {
95 i = border.getBorderInsets(c);
96 d.width += i.left + i.right;
97 }
98
99 return d;
100 }
101 return null;
102 }
103
104 protected ChangeListener createChangeListener(JPopupMenu m) {
105 return new ChangeListener() {
|
65
66 public static ComponentUI createUI(JComponent x) {
67 return new MotifPopupMenuUI();
68 }
69
70 /* This has to deal with the fact that the title may be wider than
71 the widest child component.
72 */
73 public Dimension getPreferredSize(JComponent c) {
74 LayoutManager layout = c.getLayout();
75 Dimension d = layout.preferredLayoutSize(c);
76 String title = ((JPopupMenu)c).getLabel();
77 if (titleFont == null) {
78 UIDefaults table = UIManager.getLookAndFeelDefaults();
79 titleFont = table.getFont("PopupMenu.font");
80 }
81 FontMetrics fm = c.getFontMetrics(titleFont);
82 int stringWidth = 0;
83
84 if (title!=null) {
85 stringWidth += getTextUIDrawing().getStringWidth(c, fm, title);
86 }
87
88 if (d.width < stringWidth) {
89 d.width = stringWidth + 8;
90 Insets i = c.getInsets();
91 if (i!=null) {
92 d.width += i.left + i.right;
93 }
94 if (border != null) {
95 i = border.getBorderInsets(c);
96 d.width += i.left + i.right;
97 }
98
99 return d;
100 }
101 return null;
102 }
103
104 protected ChangeListener createChangeListener(JPopupMenu m) {
105 return new ChangeListener() {
|