我正在调整JPopupMenu的大小,虽然我可以很好地调整字体和菜单项的大小,但我无法调整其他菜单的大小。例如。用于扩展菜单的快捷方式标签或箭头仍然很小;从这里可以看出:
例如,“Ctrl + C”标签(或“字体”旁边的箭头)在两个菜单中具有相同的大小,即使我希望它在缩放菜单中更大。我怎么能做到这一点?
这是我调整字体和菜单项大小的方法
//aCollection is a collection with menu items (separators, jmenuitems, etc.) which i want to resize
//aJContainer is a container (JPopupMenu in this case) where I'm adding the resized components
private void addCollectionToJContainer(JComponent aJContainer, Collection aCollection){
double WEBSTART_ZOOM_FACTOR = 2.5;
Iterator i = aCollection.iterator();
while (i.hasNext()) {
JComponent item = (JComponent) i.next();
try{
Font f = ((JMenuItem) item).getFont();
((JMenuItem) item).setFont(new Font(f.getName(), f.getStyle(), (int) Math.round(f.getSize() * WEBSTART_ZOOM_FACTOR)));
int w = (int) Math.round(item.getPreferredSize().getWidth() * WEBSTART_ZOOM_FACTOR);
int h = (int) Math.round(item.getPreferredSize().getHeight() * WEBSTART_ZOOM_FACTOR);
item.setPreferredSize(new Dimension(w, h));
}catch(ClassCastException e){ //item is a separator
}
aJContainer.add(item);
}
}