java - How to set the minimum height and icon with of a text menu or context menu item? -
i use big icons in text menus in swing. icons cause menu row expand if icon set menu item. leads inhomogeneous position of following label , different distance between menu items if there menu items without icons or icons of smaller size.
i may now:
- resize icons
- insert empty, transparent icons menu items without icon
- ?
are there other ways set minimum size of menu items icon spacer icon-less menu items in text menus?
best practice add empty/transparent icons menu items w/o icons. can merge icons (to create sames width/height) method:
private static icon mergeicons(icon icon1, icon icon2, int x, int y, component c) { int w = 0, h = 0; if (icon1 != null) { w = icon1.geticonwidth(); h = icon1.geticonheight(); } if (icon2 != null) { w = icon2.geticonwidth() + x > w ? icon2.geticonwidth() + x : w; h = icon2.geticonheight() + y > h ? icon2.geticonheight() + y : h; } if (w < 1) w = 16; if (h < 1) h = 16; java.awt.image.colormodel model = java.awt.graphicsenvironment.getlocalgraphicsenvironment (). getdefaultscreendevice ().getdefaultconfiguration (). getcolormodel (java.awt.transparency.bitmask); java.awt.image.bufferedimage buffimage = new java.awt.image.bufferedimage (model, model.createcompatiblewritableraster (w, h), model.isalphapremultiplied (), null); java.awt.graphics g = buffimage.creategraphics (); if (icon1 != null) { icon1.painticon(c, g, 0, 0); } if (icon2 != null) { icon2.painticon(c, g, x, y); } g.dispose(); return new imageicon(buffimage); }
Comments
Post a Comment