How to disable JPanel so that it cannot resize in Java

I have several JPanels in the layout and whenever I manually resize the JFrame with the mouse, it stretches the JPanels and makes it useless. Is there any way to disable this?

+3
source share
3 answers

JPanel is not changed by the user.

If you mean JFrame, you can use

yourFrame.setResizable(false);
+7
source

LayoutManager, . LayoutManager, BorderLayout, , . , , . LayoutManager - TableLayout, . , . , .

MaximumSize JFrame, JFrame.

+3

, @Shehzad @chubbsondubs.

, , "resizable" JPanel. , , , ( ). , . chubbsondubs, , . :

  add(contextPanel, BorderLayout.CENTER);
  add(btnPanel, BorderLayout.SOUTH);
  add(sidebar, BorderLayout.WEST);

. sidebar , GridBagLayout , . preferredSize, minimumSize maximumSize , , "" , sidebar ( , , ). () , sidebar . sidebar , . , " " , .

  JPanel dummyPane = new JPanel();
  dummyPane.add(sidePanel);

  add(contextPanel, BorderLayout.CENTER);
  add(btnPanel, BorderLayout.SOUTH);
  add(dummyPane, BorderLayout.WEST);

dummyPane "" , sidebar .

UPDATE:

: , size, preferredSize, minimumSize maximumSize. . - null, x, y . size setSize(int width, int height) setBounds(int x, int y, int width, int height).

+2
source

All Articles