JFrame initially appears with a maximum width limited to my monitor width
up vote
1
down vote
favorite
I'm experiencing a strange problem with the java JFrame
class in one of my programs. Thankfully I'm able to duplicate this issue using the FrameDemo.java
example taken from Oracle's website:
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/FrameDemoProject/src/components/FrameDemo.java
I change the dimension of emptyLabel
to (3005, 100) and then compile and launch the program. On my dual monitor display, I expect the frame to almost span both monitors (they're each 1920 pixels wide).
Instead, what I'm seeing is that the JFrame
is sized to fit the width of a single monitor. I can't seems to get the window to come up spanning both monitors. Am I doing something wrong here? I'm running on Centos 7.5 and am using jdk 1.8.0_60.
The exact code appears below. It's mostly a copy/paste from Oracle's demo, with some comments cut to keep it short.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* FrameDemo.java requires no other files. */
public class FrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("blahblah");
emptyLabel.setPreferredSize(new Dimension(3005, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
java swing jframe
|
show 1 more comment
up vote
1
down vote
favorite
I'm experiencing a strange problem with the java JFrame
class in one of my programs. Thankfully I'm able to duplicate this issue using the FrameDemo.java
example taken from Oracle's website:
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/FrameDemoProject/src/components/FrameDemo.java
I change the dimension of emptyLabel
to (3005, 100) and then compile and launch the program. On my dual monitor display, I expect the frame to almost span both monitors (they're each 1920 pixels wide).
Instead, what I'm seeing is that the JFrame
is sized to fit the width of a single monitor. I can't seems to get the window to come up spanning both monitors. Am I doing something wrong here? I'm running on Centos 7.5 and am using jdk 1.8.0_60.
The exact code appears below. It's mostly a copy/paste from Oracle's demo, with some comments cut to keep it short.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* FrameDemo.java requires no other files. */
public class FrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("blahblah");
emptyLabel.setPreferredSize(new Dimension(3005, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
java swing jframe
This "may" be a limitation of the OS
– MadProgrammer
Nov 8 at 20:57
I'm starting to think this might be the case. I have learned that a JFrame is associated with a GraphicsConfiguration (gc). As all my gc devices are 1920x1080 in size, I'm starting to think that the JFrame may be limited to this size.
– user2643390
Nov 8 at 21:13
Interestingly, if I call frame.setMinimumSize(new Dimension 3500,100)); just prior to the pack statement, the window comes up spanning both monitors. I don't want to do this in a real program though.
– user2643390
Nov 8 at 21:14
1
Yes and no. You can have window larger than the physical screen, although on MacOS you'll be disappointed by the results. After a "lot" of digging, it appears that the call tosetVisible
is actually the culprit.pack
will honour the preferred size of the contents, but for some reason after callingsetVisible
, the window is constrained to the size of the monitor and I can't find exactly "where" this is getting done. "A" somewhat "nasty" solution would to callpack
(again) after callingsetVisible
🤮
– MadProgrammer
Nov 8 at 21:16
That's not nasty - it's a beautiful workaround for a nasty problem! How did you figure that out?
– user2643390
Nov 8 at 21:19
|
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm experiencing a strange problem with the java JFrame
class in one of my programs. Thankfully I'm able to duplicate this issue using the FrameDemo.java
example taken from Oracle's website:
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/FrameDemoProject/src/components/FrameDemo.java
I change the dimension of emptyLabel
to (3005, 100) and then compile and launch the program. On my dual monitor display, I expect the frame to almost span both monitors (they're each 1920 pixels wide).
Instead, what I'm seeing is that the JFrame
is sized to fit the width of a single monitor. I can't seems to get the window to come up spanning both monitors. Am I doing something wrong here? I'm running on Centos 7.5 and am using jdk 1.8.0_60.
The exact code appears below. It's mostly a copy/paste from Oracle's demo, with some comments cut to keep it short.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* FrameDemo.java requires no other files. */
public class FrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("blahblah");
emptyLabel.setPreferredSize(new Dimension(3005, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
java swing jframe
I'm experiencing a strange problem with the java JFrame
class in one of my programs. Thankfully I'm able to duplicate this issue using the FrameDemo.java
example taken from Oracle's website:
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/FrameDemoProject/src/components/FrameDemo.java
I change the dimension of emptyLabel
to (3005, 100) and then compile and launch the program. On my dual monitor display, I expect the frame to almost span both monitors (they're each 1920 pixels wide).
Instead, what I'm seeing is that the JFrame
is sized to fit the width of a single monitor. I can't seems to get the window to come up spanning both monitors. Am I doing something wrong here? I'm running on Centos 7.5 and am using jdk 1.8.0_60.
The exact code appears below. It's mostly a copy/paste from Oracle's demo, with some comments cut to keep it short.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* FrameDemo.java requires no other files. */
public class FrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("blahblah");
emptyLabel.setPreferredSize(new Dimension(3005, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
java swing jframe
java swing jframe
edited Nov 9 at 7:36
user10614001
asked Nov 8 at 20:50
user2643390
63
63
This "may" be a limitation of the OS
– MadProgrammer
Nov 8 at 20:57
I'm starting to think this might be the case. I have learned that a JFrame is associated with a GraphicsConfiguration (gc). As all my gc devices are 1920x1080 in size, I'm starting to think that the JFrame may be limited to this size.
– user2643390
Nov 8 at 21:13
Interestingly, if I call frame.setMinimumSize(new Dimension 3500,100)); just prior to the pack statement, the window comes up spanning both monitors. I don't want to do this in a real program though.
– user2643390
Nov 8 at 21:14
1
Yes and no. You can have window larger than the physical screen, although on MacOS you'll be disappointed by the results. After a "lot" of digging, it appears that the call tosetVisible
is actually the culprit.pack
will honour the preferred size of the contents, but for some reason after callingsetVisible
, the window is constrained to the size of the monitor and I can't find exactly "where" this is getting done. "A" somewhat "nasty" solution would to callpack
(again) after callingsetVisible
🤮
– MadProgrammer
Nov 8 at 21:16
That's not nasty - it's a beautiful workaround for a nasty problem! How did you figure that out?
– user2643390
Nov 8 at 21:19
|
show 1 more comment
This "may" be a limitation of the OS
– MadProgrammer
Nov 8 at 20:57
I'm starting to think this might be the case. I have learned that a JFrame is associated with a GraphicsConfiguration (gc). As all my gc devices are 1920x1080 in size, I'm starting to think that the JFrame may be limited to this size.
– user2643390
Nov 8 at 21:13
Interestingly, if I call frame.setMinimumSize(new Dimension 3500,100)); just prior to the pack statement, the window comes up spanning both monitors. I don't want to do this in a real program though.
– user2643390
Nov 8 at 21:14
1
Yes and no. You can have window larger than the physical screen, although on MacOS you'll be disappointed by the results. After a "lot" of digging, it appears that the call tosetVisible
is actually the culprit.pack
will honour the preferred size of the contents, but for some reason after callingsetVisible
, the window is constrained to the size of the monitor and I can't find exactly "where" this is getting done. "A" somewhat "nasty" solution would to callpack
(again) after callingsetVisible
🤮
– MadProgrammer
Nov 8 at 21:16
That's not nasty - it's a beautiful workaround for a nasty problem! How did you figure that out?
– user2643390
Nov 8 at 21:19
This "may" be a limitation of the OS
– MadProgrammer
Nov 8 at 20:57
This "may" be a limitation of the OS
– MadProgrammer
Nov 8 at 20:57
I'm starting to think this might be the case. I have learned that a JFrame is associated with a GraphicsConfiguration (gc). As all my gc devices are 1920x1080 in size, I'm starting to think that the JFrame may be limited to this size.
– user2643390
Nov 8 at 21:13
I'm starting to think this might be the case. I have learned that a JFrame is associated with a GraphicsConfiguration (gc). As all my gc devices are 1920x1080 in size, I'm starting to think that the JFrame may be limited to this size.
– user2643390
Nov 8 at 21:13
Interestingly, if I call frame.setMinimumSize(new Dimension 3500,100)); just prior to the pack statement, the window comes up spanning both monitors. I don't want to do this in a real program though.
– user2643390
Nov 8 at 21:14
Interestingly, if I call frame.setMinimumSize(new Dimension 3500,100)); just prior to the pack statement, the window comes up spanning both monitors. I don't want to do this in a real program though.
– user2643390
Nov 8 at 21:14
1
1
Yes and no. You can have window larger than the physical screen, although on MacOS you'll be disappointed by the results. After a "lot" of digging, it appears that the call to
setVisible
is actually the culprit. pack
will honour the preferred size of the contents, but for some reason after calling setVisible
, the window is constrained to the size of the monitor and I can't find exactly "where" this is getting done. "A" somewhat "nasty" solution would to call pack
(again) after calling setVisible
🤮– MadProgrammer
Nov 8 at 21:16
Yes and no. You can have window larger than the physical screen, although on MacOS you'll be disappointed by the results. After a "lot" of digging, it appears that the call to
setVisible
is actually the culprit. pack
will honour the preferred size of the contents, but for some reason after calling setVisible
, the window is constrained to the size of the monitor and I can't find exactly "where" this is getting done. "A" somewhat "nasty" solution would to call pack
(again) after calling setVisible
🤮– MadProgrammer
Nov 8 at 21:16
That's not nasty - it's a beautiful workaround for a nasty problem! How did you figure that out?
– user2643390
Nov 8 at 21:19
That's not nasty - it's a beautiful workaround for a nasty problem! How did you figure that out?
– user2643390
Nov 8 at 21:19
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
Many thanks to MadProgrammer. Unfortunately, in my more complicated program, the second call to pack didn't seem to do the trick.
The workaround I eventually settled on was to compute the cumulative width of all my components (they were loaded into a JSplitPane). This is equal to the widths of the left pane, the right pane and the divider. If this cumulative width exceeds the width of a monitor, I set frame minimum size to this cumulative width. This seems to ensure that the frame can span two monitors when it appears. Then after making things visible, I reset the minimum size to a value I saved at startup time. This allows my JFrame to come up on two screens but still be resizable to something smaller.
This truly is a nasty workaround. I have reported this as a bug to http://bugs.java.com. It's listed as the following bug: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8213620
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Many thanks to MadProgrammer. Unfortunately, in my more complicated program, the second call to pack didn't seem to do the trick.
The workaround I eventually settled on was to compute the cumulative width of all my components (they were loaded into a JSplitPane). This is equal to the widths of the left pane, the right pane and the divider. If this cumulative width exceeds the width of a monitor, I set frame minimum size to this cumulative width. This seems to ensure that the frame can span two monitors when it appears. Then after making things visible, I reset the minimum size to a value I saved at startup time. This allows my JFrame to come up on two screens but still be resizable to something smaller.
This truly is a nasty workaround. I have reported this as a bug to http://bugs.java.com. It's listed as the following bug: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8213620
add a comment |
up vote
0
down vote
Many thanks to MadProgrammer. Unfortunately, in my more complicated program, the second call to pack didn't seem to do the trick.
The workaround I eventually settled on was to compute the cumulative width of all my components (they were loaded into a JSplitPane). This is equal to the widths of the left pane, the right pane and the divider. If this cumulative width exceeds the width of a monitor, I set frame minimum size to this cumulative width. This seems to ensure that the frame can span two monitors when it appears. Then after making things visible, I reset the minimum size to a value I saved at startup time. This allows my JFrame to come up on two screens but still be resizable to something smaller.
This truly is a nasty workaround. I have reported this as a bug to http://bugs.java.com. It's listed as the following bug: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8213620
add a comment |
up vote
0
down vote
up vote
0
down vote
Many thanks to MadProgrammer. Unfortunately, in my more complicated program, the second call to pack didn't seem to do the trick.
The workaround I eventually settled on was to compute the cumulative width of all my components (they were loaded into a JSplitPane). This is equal to the widths of the left pane, the right pane and the divider. If this cumulative width exceeds the width of a monitor, I set frame minimum size to this cumulative width. This seems to ensure that the frame can span two monitors when it appears. Then after making things visible, I reset the minimum size to a value I saved at startup time. This allows my JFrame to come up on two screens but still be resizable to something smaller.
This truly is a nasty workaround. I have reported this as a bug to http://bugs.java.com. It's listed as the following bug: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8213620
Many thanks to MadProgrammer. Unfortunately, in my more complicated program, the second call to pack didn't seem to do the trick.
The workaround I eventually settled on was to compute the cumulative width of all my components (they were loaded into a JSplitPane). This is equal to the widths of the left pane, the right pane and the divider. If this cumulative width exceeds the width of a monitor, I set frame minimum size to this cumulative width. This seems to ensure that the frame can span two monitors when it appears. Then after making things visible, I reset the minimum size to a value I saved at startup time. This allows my JFrame to come up on two screens but still be resizable to something smaller.
This truly is a nasty workaround. I have reported this as a bug to http://bugs.java.com. It's listed as the following bug: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8213620
edited Nov 9 at 14:43
answered Nov 8 at 22:26
user2643390
63
63
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215927%2fjframe-initially-appears-with-a-maximum-width-limited-to-my-monitor-width%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This "may" be a limitation of the OS
– MadProgrammer
Nov 8 at 20:57
I'm starting to think this might be the case. I have learned that a JFrame is associated with a GraphicsConfiguration (gc). As all my gc devices are 1920x1080 in size, I'm starting to think that the JFrame may be limited to this size.
– user2643390
Nov 8 at 21:13
Interestingly, if I call frame.setMinimumSize(new Dimension 3500,100)); just prior to the pack statement, the window comes up spanning both monitors. I don't want to do this in a real program though.
– user2643390
Nov 8 at 21:14
1
Yes and no. You can have window larger than the physical screen, although on MacOS you'll be disappointed by the results. After a "lot" of digging, it appears that the call to
setVisible
is actually the culprit.pack
will honour the preferred size of the contents, but for some reason after callingsetVisible
, the window is constrained to the size of the monitor and I can't find exactly "where" this is getting done. "A" somewhat "nasty" solution would to callpack
(again) after callingsetVisible
🤮– MadProgrammer
Nov 8 at 21:16
That's not nasty - it's a beautiful workaround for a nasty problem! How did you figure that out?
– user2643390
Nov 8 at 21:19