sashka, Картинки ч-з ...setIcon(...), а плавный переход можно примерно в таком ключе:
| Код | import java.awt.*; import javax.swing.*; import javax.swing.plaf.PopupMenuUI;
/** * JMenu with gradient background. * This implementstion shows only the idea of how to do such tasks. * @author Alexander Kabanov */ public class JGradientMenu extends JMenu { private Color topLeftColor; private Color bottomRightColor;
public JGradientMenu(String name, Color topLeftColor, Color bottomRightColor) { super(name); this.topLeftColor = topLeftColor; this.bottomRightColor = bottomRightColor; getPopupMenu().setUI(new GradientPopupMenuUI()); }
public JMenuItem add(JMenuItem menuItem) { menuItem.setOpaque(false); return super.add(menuItem); }
private class GradientPopupMenuUI extends PopupMenuUI { public void paint(Graphics g, JComponent c) { Graphics2D graphics = (Graphics2D) g; Paint paint = new GradientPaint(0, 0, topLeftColor, c.getWidth(), c.getHeight(), bottomRightColor); graphics.setPaint(paint); graphics.fillRect(0, 0, c.getWidth(), c.getHeight()); super.paint(g, c); } }
/** * Test starter */ public static void main(String[] args) { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JGradientMenu("Colours", Color.YELLOW, Color.CYAN); menuBar.add(menu); String[] menues = {"First", "Second", "Third", "Fourth", "Fifth"}; for (String name : menues) { menu.add(new JMenuItem(name)); }
JFrame testFrame = new JFrame("Gradient Menu Test Frame"); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); testFrame.setSize(300, 200); testFrame.setJMenuBar(menuBar); testFrame.setVisible(true); } }
|
Показана только идея. Это далеко не универсальный вариант |