2

Possible Duplicate:
Example Program JMenubar on JInternalFrame when i Maximize the JInternalFrame

i am working on a Swing application, and i am new with the Layouts, i want my JFrame and the included JInternalFrames to take the size of the screen when the JFrame is maximizable or resizable, i've added a Grid Layout but it didn't work. So i am asking how to add the appropriate layout and how to implement it :D. please help.

Community
  • 1
  • 1
Zakaria Marrah
  • 755
  • 6
  • 15
  • 28
  • 2
    See this example if I understand you correctly (I think the problem though is you don't use `JDesktopPane` which should be used in conjunction with `JInternalFrame`s): see [this answer](http://stackoverflow.com/questions/13651991/example-program-jmenubar-on-jinternalframe-when-i-maximize-the-jinternalframe/13652087#13652087) for an example – David Kroukamp Dec 10 '12 at 13:08

2 Answers2

3

As an example of @Catalina's idea, you can use setFullScreenWindow(), as shown here, and add the JDesktopPane to the frame's center. Don't forget to pack() your internal frames, too.

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;

/**
 * @see https://stackoverflow.com/a/13806057/230513
 * @see https://stackoverflow.com/questions/7456227
 */
public class FullScreenTest {

    public static final String TITLE = "Full Screen Test";
    private final JFrame f = new JFrame(TITLE);
    private final JDesktopPane jdp = new JDesktopPane();

    public FullScreenTest() {
    }

    private void display() {
        GraphicsEnvironment env =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice dev = env.getDefaultScreenDevice();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JInternalFrame jif = new JInternalFrame(TITLE, true, true, true);
        jif.add(new JLabel(TITLE + " " + TITLE), BorderLayout.NORTH);
        jif.add(new JLabel(TITLE + " " + TITLE), BorderLayout.CENTER);
        jif.add(new JLabel(TITLE + " " + TITLE), BorderLayout.SOUTH);
        jif.pack();
        jif.setLocation(100, 100);
        jif.setVisible(true);
        jdp.add(jif);
        f.add(jdp, BorderLayout.CENTER);
        dev.setFullScreenWindow(f);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new FullScreenTest().display();
            }
        });
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
2

You really need to put your JInternalFrame in a JDesktopPane, like they shown in How to Use Internal Frames. If you use a GridLayout on your JFrame, your JDesktopPane will grow with the frame. You already know how to make the frame fit the screen, like here.

Community
  • 1
  • 1
Catalina Island
  • 7,027
  • 2
  • 23
  • 42