Full-screen with messageDialog?
I've have this full-screen window with a button which create a message dialog:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
publicclass Main{
publicstaticvoid main(String[] args){
// Determine if full-screen mode is supported directly
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
// Create a window for full-screen mode; add a button to leave full-screen mode
JFrame frame =new JFrame(gs.getDefaultConfiguration());
JWindow win =new JWindow(frame);
//creating panels
JPanel bottomPanel =new JPanel(new FlowLayout(FlowLayout.RIGHT));
//inserts into bottomPanel
JButton dialogButton =new JButton("Show dialog");
JButton exitButton =new JButton("Exit");
bottomPanel.add(dialogButton);
bottomPanel.add(exitButton);
//inserts panels
win.add(bottomPanel, BorderLayout.SOUTH);
//create a button listener to show a dialog
dialogButton.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent evt){
JOptionPane.showMessageDialog(null,"Error","Here is an error", JOptionPane.ERROR_MESSAGE);
}
});
// Create a button listener that leaves full-screen mode
exitButton.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent evt){
// Return to normal windowed mode
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
gs.setFullScreenWindow(null);
System.exit(0);
}
});
frame.setVisible(true);
try{
gs.setFullScreenWindow(win);
win.validate();
}catch (Exception ex){
System.out.println(ex);
}
}
}
As you see you can't see the dialog when clicking the button.
What can I do so that I can see the dialog?
Hi,
You could try to declare your JFrame as final and open your dialog with this frame as parent in order to be sure that it will be over the frame.
final JFrame frame = new JFrame(gs.getDefaultConfiguration());
....
JOptionPane.showMessageDialog(frame , "Error", "Here is an error", JOptionPane.ERROR_MESSAGE);
Regards,
nemoleo
Well, now I got this code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main {
public static void main(String[] args) {
// Determine if full-screen mode is supported directly
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
// Create a window for full-screen mode; add a button to leave full-screen mode
final JFrame frame = new JFrame(gs.getDefaultConfiguration());
JWindow win = new JWindow(frame);
//creating panels
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
//inserts into bottomPanel
JButton dialogButton = new JButton("Show dialog");
JButton exitButton = new JButton("Exit");
bottomPanel.add(dialogButton);
bottomPanel.add(exitButton);
//inserts panels
win.add(bottomPanel, BorderLayout.SOUTH);
//create a button listener to show a dialog
dialogButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog(frame, "Error", "Here is an error", JOptionPane.ERROR_MESSAGE);
}
});
// Create a button listener that leaves full-screen mode
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// Return to normal windowed mode
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
gs.setFullScreenWindow(null);
System.exit(0);
}
});
frame.setVisible(true);
try {
gs.setFullScreenWindow(win);
win.validate();
} catch (Exception ex) {
System.out.println(ex);
}
}
}
But I can't see the Dialog :(
Hope you can help me.
what dialog ? this :
public void actionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog(frame, "Error", "Here is an error", JOptionPane.ERROR_MESSAGE);
}
});
O.o ?
Yes, I don't got the JOptionPane when clicking the button.
> Yes, I don't got the JOptionPane when clicking the
> button.
I tested you program and I could the the text and icon the the JOptionPane, but nothing else (like the frame around). I searched the problem, and other people have had problems with it, but I could find an answer.
http://onesearch.sun.com/search/onesearch/index.jsp?qt=joptionpane+full+screen&col=developer-forums&rt=true&site=dev&cs=false&chooseCat=javaall
So you think it's a system problem and not a bad-code problem?
I have no idea. You might want to search the [url http://bugs.sun.com/bugdatabase/index.jsp]Bug Database[/url] to see if its a bug. Im sure theres some way to fix it though.
works OK for me - winxp pro, java 1.5.0_05try reducing your pc's hardware acceleration
> works OK for me - winxp pro, java 1.5.0_05Really? You see the frame aroundd it and everything? I see the icon, text, and button (which is not clickable). Im using 1.5.0_07.
No my SuSE Linux I see nothing when clicking the button. On my XP machine I see the frame, but when trying to move it, resize or something like that I cant see it.
> but when trying to move it, resize or something like that I cant see it.
why didn't you mention that to start with?
The optionPane shows up fine for me - frame/buttons etc, but when I move it,
it more or less disappears.
I reduced the hardware acceleration by 3 notches, re-ran the program - now
it appears OK and moves around the screen OK - just like you would expect.
Only hiccup is it appears at location (0,0), not centered - no idea why
I thought Java had the same behaviur on Windows and Linux machines - whats why..What do you mean with:I reduced the hardware acceleration by 3 notches ?
> I thought Java had the same behaviur on Windows and Linux machines - whats why..
nothing to do with my earlier question - I was asking why you didn't mention the
steps to produce the problem. No one here is a mind reader.
for hardware acceleration on xp
control panel/display/settings/advanced/troubleshoot
Sorry, when creating this topic I havn't tested my code on my XP-machine, so I didn't know, that I could see it on XP and that it disapears when moving it.
Also works for me, on jre1.5.0_04 and windows XP pro, I've tried at home on a mustang rc-bin-b104 and windows XP and it is also working (but there is a little paint problem with the full screen frame).
Have you tried to make your windowcomponents painted by the jvm instead of your OS?
(At the beginning of your code)
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
Maybe this could solve some system problem.
Will you show your idea in my code-example?
Sure :
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class DialogTest {
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
// Determine if full-screen mode is supported directly
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
// Create a window for full-screen mode; add a button to leave
// full-screen mode
final JFrame frame = new JFrame(gs.getDefaultConfiguration());
// creating panels
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// inserts into bottomPanel
JButton dialogButton = new JButton("Show dialog");
JButton exitButton = new JButton("Exit");
bottomPanel.add(dialogButton);
bottomPanel.add(exitButton);
// inserts panels
frame.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
// create a button listener to show a dialog
dialogButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog(frame, "Error",
"Here is an error", JOptionPane.ERROR_MESSAGE);
}
});
// Create a button listener that leaves full-screen mode
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// Return to normal windowed mode
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
gs.setFullScreenWindow(null);
System.exit(0);
}
});
try {
if (gs.isFullScreenSupported()) {
gs.setFullScreenWindow(frame);
}
} catch (Exception ex) {
System.out.println(ex);
}
frame.setVisible(true);
}
Well, experts can correct me, but it seems to me that the setDefaultLookAndFeelDecorated(false) method allow the OS to paint the corresponding Window, whereas when it is used with a true parameter, the jvm paint the border, the menu and some on.
What makes me conclude this is that when I set it to false, the behaviour of my JFrame is the same as any other WindowXP frame (the resize and move behaviour for example and some others details), and when it is at true the behaviour is very specific to my jvm.
I didn't try this on linux/unix environment, and it is possible that on these OS the jvm always paint Windows by default, so my remarque would not solve the problem. You can try and test the
JFrame.isDefaultLookAndFeelDecorated()
value without modifying it to see.
PS : I've simplified your code, do you really need a window? or a mere JFrame is enough?
When running your code I can't see the frame.
Swing has mysteries sometimes...
Have you tried to avoid GraphicsEnvironment, which might raise the problem here, using a setExtendedState(Frame.MAXIMIZED_BOTH); instead :
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class DialogTest {
public static void main(String[] args) {
// Create a window for full-screen mode; add a button to leave
// full-screen mode
final JFrame frame = new JFrame();//gs.getDefaultConfiguration());
// creating panels
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// inserts into bottomPanel
JButton dialogButton = new JButton("Show dialog");
JButton exitButton = new JButton("Exit");
bottomPanel.add(dialogButton);
bottomPanel.add(exitButton);
// inserts panels
frame.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
// create a button listener to show a dialog
dialogButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog(frame, "Error",
"Here is an error", JOptionPane.ERROR_MESSAGE);
}
});
// Create a button listener that leaves full-screen mode
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.exit(0);
}
});
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setVisible(true);
}
}
The last rabbit in my hat. ;-)
