0

I wanted to change button size in JMenu. I've been trying to make it with setPreferredSize(new Dimension()) method, but it does work only in horizontal way. I was looking for thread with this problem but i couldn't find anything. Woluld you help me?

the result is

and the fragment of code:

JMenuBar menubar = new JMenuBar();
JButton jcolor = new JButton();
jcolor.setBackground(Shapes.color);
jcolor.setPreferredSize(new Dimension(100, 100));
menubar.add(jcolor);
setJMenuBar(menubar);

1 Answers1

0

set the Layout of the MenuBar to null and set its own bounds then add any component you want with the size you want, but you've to setup the bounds for the component you want to add

EX:

menubar.setLayout(null);
menubar.setBounds(x, y, width, height);
JButton jcolor = new JButton();
jcolor.setBackground(Shapes.color);
jcolor.setBounds(x, y, width, height);
menubar.add(jcolor);
Jamal Alkelani
  • 606
  • 7
  • 19