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?

[3574 byte] By [Dennis_Madsena] at [2007-10-3 10:49:28]
# 1

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

nemoleoa at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 2

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.

Dennis_Madsena at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 3

what dialog ? this :

public void actionPerformed(ActionEvent evt) {

JOptionPane.showMessageDialog(frame, "Error", "Here is an error", JOptionPane.ERROR_MESSAGE);

}

});

O.o ?

Java__Estudantea at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 4
Yes, I don't got the JOptionPane when clicking the button.
Dennis_Madsena at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 5

> 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

CaptainMorgan08a at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 6
So you think it's a system problem and not a bad-code problem?
Dennis_Madsena at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 7
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.
CaptainMorgan08a at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 8
works OK for me - winxp pro, java 1.5.0_05try reducing your pc's hardware acceleration
Michael_Dunna at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 9
> 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.
CaptainMorgan08a at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 10
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.
Dennis_Madsena at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 11

> 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

Michael_Dunna at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 12
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 ?
Dennis_Madsena at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 13

> 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

Michael_Dunna at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 14
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.
Dennis_Madsena at 2007-7-15 6:14:21 > top of Java-index,Desktop,Core GUI APIs...
# 15
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).
nemoleoa at 2007-7-21 13:29:03 > top of Java-index,Desktop,Core GUI APIs...
# 16

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.

nemoleoa at 2007-7-21 13:29:03 > top of Java-index,Desktop,Core GUI APIs...
# 17
Will you show your idea in my code-example?
Dennis_Madsena at 2007-7-21 13:29:03 > top of Java-index,Desktop,Core GUI APIs...
# 18

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?

nemoleoa at 2007-7-21 13:29:03 > top of Java-index,Desktop,Core GUI APIs...
# 19
When running your code I can't see the frame.
Dennis_Madsena at 2007-7-21 13:29:03 > top of Java-index,Desktop,Core GUI APIs...
# 20

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

nemoleoa at 2007-7-21 13:29:03 > top of Java-index,Desktop,Core GUI APIs...