Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the insets of a JFrame?

Is there a way to set the insets of a JFrame? I tried

frame.getContentPane().getInsets().set(10, 10, 10, 10);

and

frame.getInsets().set(10, 10, 10, 10);

but none of them seem to work.

like image 536
JavaNewbie_M107 Avatar asked Jan 02 '13 05:01

JavaNewbie_M107


People also ask

What is insets in Java Swing?

An Insets object is a representation of the borders of a container. It specifies the space that a container must leave at each of its edges. The space can be a border, a blank space, or a title.

How do I change the resolution of a JFrame?

Firstly, we use getScreenSize() method of the Java Toolkit class to get the resolution of the screen in dots per inch. Secondly, we use the frame. setSize() to set the dimensions that we receive from the getScreenSize() method. This method contains width as the first parameter and height as the second parameter.

How do I make a JFrame maximized?

By default, we can minimize a JFrame by clicking on minimize button and maximize a JFrame by clicking on maximize button at the top-right position of the screen. We can also do programmatically by using setState(JFrame. ICONIFIED) to minimize a JFrame and setState(JFrame. MAXIMIZED_BOTH) to maximize a JFrame.


2 Answers

Overriding the Insets of JFrame would not be the soultion to your actual problem. To answer your question, you cannot set the Insets of JFrame. You should extend JFrame and override the getInsets method to give the insets you require.

like image 188
basiljames Avatar answered Oct 19 '22 03:10

basiljames


JPanel contentPanel = new JPanel();

Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10);

contentPanel.setBorder(padding);

yourFrame.setContentPane(contentPanel);

So basically, contentPanel is the main container of your frame.

like image 37
Mark Vizcarra Avatar answered Oct 19 '22 01:10

Mark Vizcarra