Saving JButton size in BorderLayout.CENTER

Is there a way to keep JButton's natural size in the center of BorderLayout? Right now, it is expanding in all directions to fill it, but I want its normal size.

If this is not possible, how can I make the button be in the center of the panel with its normal size?

+3
source share
5 answers

I suggest going straight to GridBagLayout. Although it has odd behavior and a bad interface, it is a standard layout that does almost everything. You will need this, so you can use the same layout manager sequentially, even if it is not absolutely necessary.

+4

BorderLayout , , JPanel FlowLayout, CENTER.

JPanel borderPanel = new JPanel(new BorderLayout());
JButton theButton = new JButton("Click Me");
JPanel flowPanel = new JPanel(new FlowLayout());
flowPanel.add(theButton);
borderPanel.add(BorderLayout.CENTER, flowPanel);
+14

, BorderLayout, , . .

+1

GridBagLayout . GridBagLayout - JPanel MigLayout, ( )

+1

, BorderLayout. .

" " .

0

Source: https://habr.com/ru/post/1708310/


All Articles