简体   繁体   中英

How to maximize a the height of a JFrame?

Windows doesn't support myFrame.setExtendedState(JFrame.MAXIMIZED_VERT); .

So I tried to get the screen size and made the JFrames height as big as the screens height. But then it covers the Windows taskbar.

Is there any other way to maximize my JFrame vertcially?

Thanks,

esanits

try this out, buddy:

Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(t.getGraphicsConfiguration());
int taskHeight=screenInsets.bottom;       
System.out.println(taskHeight);  

Here is one way to get basic info about the window and the frame:

import java.awt.*;
import javax.swing.*;

public class FrameInfo
{
    public static void main(String[] args)
    {
        String laf = "javax.swing.plaf.metal.MetalLookAndFeel";
//        laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
//        laf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";

//        try { UIManager.setLookAndFeel( laf ); }
//        catch (Exception e) { System.out.println(e); }
//        JFrame.setDefaultLookAndFeelDecorated(true);

        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle bounds = env.getMaximumWindowBounds();
        System.out.println("Screen Bounds: " + bounds );

        GraphicsDevice screen = env.getDefaultScreenDevice();
        GraphicsConfiguration config = screen.getDefaultConfiguration();
        System.out.println("Screen Size  : " + config.getBounds());
        System.out.println(Toolkit.getDefaultToolkit().getScreenSize());

        JFrame frame = new JFrame("Frame Info");
        System.out.println("Frame Insets : " + frame.getInsets() );

        frame.setSize(200, 200);
//        frame.pack();
        System.out.println("Frame Insets : " + frame.getInsets() );
        frame.setVisible( true );

        System.out.println("Frame Size   : " + frame.getSize() );
        System.out.println("Frame Insets : " + frame.getInsets() );
        System.out.println("Content Size : " + frame.getContentPane().getSize() );
     }
}

I'm not sure if this is the best way, but it worked for me...

    Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(mainScreen.getGraphicsConfiguration());
    int taskHeight=screenInsets.bottom;
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    mainScreen.setSize(d.width/2, d.height - taskHeight);
    mainScreen.setLocation(d.width/2, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM