Reputation: 197
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
Upvotes: 2
Views: 1322
Reputation: 45
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);
Upvotes: 0
Reputation: 324098
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() );
}
}
Upvotes: 1
Reputation: 289
try this out, buddy:
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(t.getGraphicsConfiguration());
int taskHeight=screenInsets.bottom;
System.out.println(taskHeight);
Upvotes: 3