i am trying to set size of JButton, but by default it take whole frame, it's height easily set but i can't set it's width & why its behaving like that i don't know.
my code :
JButton btnNewButton = new JButton("");
btnNewButton.setPreferredSize(new Dimension(32,0));
ImageIcon icon = new ImageIcon(this.getClass().getResource("/images/images_Left.png"));
btnNewButton.setIcon(icon);
boxTlacitek.add(btnNewButton);
getContentPane().add(btnNewButton, BorderLayout.NORTH);
any suggestion please ?
Change the layout. Try adding the button to another
JPanelthen add the panel the frame.BorderLayoutwill stretch the button across the available width of the panel when the component is placed in theNORTHorSOUTHposition