如何最大化 JFrame 的高度?

发布于 2024-10-20 05:07:59 字数 202 浏览 5 评论 0原文

Windows 不支持 myFrame.setExtendedState(JFrame.MAXIMIZED_VERT);

所以我尝试获取屏幕尺寸并使 JFrames 高度与屏幕高度一样大。但随后它会覆盖 Windows 任务栏。

还有其他方法可以垂直最大化我的 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神魇的王 2024-10-27 05:07:59

试试这个,伙计:

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

try this out, buddy:

Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(t.getGraphicsConfiguration());
int taskHeight=screenInsets.bottom;       
System.out.println(taskHeight);  
拥醉 2024-10-27 05:07:59

以下是获取有关窗口和框架的基本信息的一种方法:

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() );
     }
}

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() );
     }
}
只涨不跌 2024-10-27 05:07:59

我不确定这是否是最好的方法,但它对我有用......

    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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文