Why the JInterFrame not resizing? - java

I am creating one java Application which includes the JDesktopPane and JInternalFrame.
And I am using GridLayOut to set JInternalFrame
The Issue is I can't resize the JInternalFrame as per the GridLayout size
Below is One Screen Shot of Application
I want the JInnernalFrame as the grid size.
Please do help me.

Because JInternalFrames are suppose to be added to and managed by a JDesktopPane
Take a look at How to Use Internal Frames for more details
JDesktopPane isn't suppose to have a layout manager, the GridLayout is taking control and making decision about how the JInternalFrame should be managed.
Simple answer is, don't use a layout manager with a JDesktopPane. Instead use JInternalFrame#pack to size the frames, setLocation to place it and don't forget to make it visible
I want the JInnernalFrame as the grid size
Either don't use JInternalFrames this way, or provide functionality that can mimic this when you want it. Layout managers tend to be to rigid for providing both these functionalities

Related

change the size of panels inside a desktopPane when it's size changes

I´m using this code for starting the desktopPane maximized
this.setExtendedState(MAXIMIZED_BOTH);
When the jDesktopPane displays it's maximized, but the panels inside are the same size and I don't know how to resize them. I want the panels to resize too
For the JPanel inside your JDesktopPane, you need to implement layout manager. Then those panel resize based on the layout manager. For example, Here is tutorial how to use FlowLayoutManager
I implemented Layout Manager, but used Free Design Instead of Flow Layout, it was easier to me and I got the results I wanted

Java Swing Application Fullscreen mode

I'm working on a Swing Application. The application needs to be in fullscreen all the time including its components. I made the application fullscreen using frmSwingapplication.setExtendedState(Frame.MAXIMIZED_BOTH);
The JFrame contains 2 JPanels. One has JTree and upon the selection of node of the JTree, a new panel is painted in another JPanel.
The problem is, when the application is minimized, it looks like
However when I maximize it, it looks like That is, only covering the portion it did while minimized. How can I resolve this issue? I tried setting size and bounds of container I got from getContentPane() but it was all useless. I even tried it with frame.pack(); and frame.setVisible(true);
You have to use proper layout managers:
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
Certain layout managers will use all the available space and size/lay out components inside them to fill the whole area. Examples for such layout managers are BorderLayout, GridLayout.

Resize JFrame and Components Based On Computer Resoultion

I've made a java application in netbeans and am wondering how to have the size of the jframe half the width and height of the computer resolution and also having the components comply with this change. I tried putting code and it did make the frame half the height of the computer resolution but my components, such as buttons and textfields, stopped showing. How can I achieve this? Thanks.
(EDITED)
Set the JFrame's layout manager to GridLayout. In the properties window of the GridLayout itself (select in the navigator window) set columns to 1 and rows to 2. This should give you what you want and you won't have to get into the code.
This is the key code being called within the initComponents() method of your JFrame subclass (created by NetBeans) but it is important to understand where it is:
getContentPane().setLayout(new java.awt.GridLayout(2, 1));
I love Netbeans but you do have to understand the basics.
Good luck with your project. Swing is an awesome toolset that was way ahead of it's time.
As usual in this situation the key is using the right combination of layout managers for your containers. You're probably using NetBeans generated code (something I recommend you avoid until you are very comfortable with Swing coding), and it's probably having you use GroupLayout, a fine layout, but one that might not behave as well as you'd like on resizing components. I suggest that you go through the layout manager tutorial and try to nest JPanel containers and play with different layouts that re-size well such as GridLayout, GridBagLayout and BorderLayout to try to create the best layout that can re-size well.

Adding more than one JPanel in a single JFrame

I have created a JFrame - now I want to add the 4 JPanel in that frame at a particular location. How can set the location of panels in the frame?
Use (possibly nested1) layouts for the logic. See Laying Out Components Within a Container for details. They can:
Include default spacing in the constructor (often)
Calculate how big the GUI needs to be in order to display the components (in whatever PLAF, on whatever system the app. is deployed).
Extra spacing can be organized by adding an EmtpyBorder to child components.
See the nested layout example
Placing components in a container is quite a complicated subject in Swing. Instead of defining the exact places for your components, you would normally use a layout manager that arranges them in a certain way.
Here is the tutorial you should read to get a (visual) clue about the different layout managers: A Visual Guide to Layout Managers
However, the standard layout managers of Swing can be cumbersome for more complex layouts. Either, you could use nested layouts to get the desired result, or you could use a very powerful third-party library: JGoodies Forms. The downside is of course that you have to learn yet another library. Therefore, I would only recommend it for a bigger project.
For me it is good way to set GridbagLayout for the container of the frame. There are several visual swing GUI editors available to do this easily. You can use NetBeans GUI editor or GWT Designer (https://developers.google.com/web-toolkit/tools/gwtdesigner/) for complex GUI designing tasks
If its 4 locations, you can use BorderLayout,by default its the CENTRE, but it also have EAST, WEST , NORTH, SOUTH locations for the placement of the components. You can also use setLocation to put the panels in the appropriate locations, if a layout isn't used.
Its even better to use GroupLayout developed my NetBeans team in 2005, use Windows Builder Pro, now provided by google for free.
set the layout of the Frame to be null via setLayout(null)
create 4 JPanel and set their location using setLocation method
add these panels using JFrame's add method

Question to pack() method

I'm building a GUI application, and within a JFrame i have 2 jcombobox's and a JPanel to view certain data. Now when i call the pack() methode in the main class it puts the two jcombobox'es next to my JPanel, which i dont want, because I want them North. Ofcourse I've tried to hard-code it in my code, but it doesn't work after I've called the pack() method.
Are there any alternatives to this method?
Only one component can be NORTH, so if you want both ComboBoxes to be NORTH you have to add them into a separate container. This separate container can then be put NORTH.
(Post the source for more exact help.)
All pack does is resize the Window (in this case JFrame) to its preferred size and the preferred sizes of its sub-components. To control the actual location of the sub-components relative to one another you need to use an appropriate LayoutManager.
You might want to check out the Using Layout Managers tutorial.
The pack() method just causes the layouting to happen, it has abolutely nothing to do with what is put where.
Most likely you're not using layout managers correctly. Show us your code and we can tell you waht exactly you're doing wrong.
You can avoid using pack by explicitly setting the frame size with setSize and setBounds. However, using pack is usually the preferred way as it leaves the frame layout manager in charge of the frame size.
That being said, the problem you are describing appears to be related to the correct use of a layout manager rather than the sizing of the frame. Have a look at the various layout managers for Swing and how to use them: http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/layout/using.html.

Categories