Here is my code. The button is the same size as the FlowLayout. How can I make the button smaller?
public class javalearning extends JFrame{{
FlowLayout f = new FlowLayout();
this.setSize(600,600);
JFrame j = new JFrame();
this.setTitle("this is a tittle");
JButton button = new JButton();
button.setText("Button");
this.add(button);
button.setBounds(10, 10, 10, 10);
this.setVisible(true);
}
}
FlowLayoutwill lay out Components left-to-right (or right-to-left) wrapping them if required. If you wish to explicitly set the size of eachJButtonyou should usesetPreferredSizerather thansetSizeorsetBoundsas layout managers typically make use of the minimum, preferred and maximum sizes when performing a layout.