I'm writing a program using Swing and AWT and I have a JFrame that is fullscreen. On said frame I have a button that opens a JDialog on that frame. When I click the button it does create the jDialog but it makes my screen look like it's having a siezure. Please help. Is there any way to make a popup menu that does the equivilent of grab_set(), does not move, and can hold objects?
Code for fullscreen
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//
public class test {
public static void main(String[] args)
{
GraphicsEnvironment graphics = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = graphics.getDefaultScreenDevice();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setUndecorated(true);
f.setResizable(false);
JMenuBar mb = new JMenuBar();
mb.setLayout(new BorderLayout());
JButton x = new JButton("X");
Listeners close_button= new Listeners();
x.addActionListener(close_button.close());
x.setPreferredSize(new Dimension(30,30));
mb.add(x, BorderLayout.EAST);
f.setJMenuBar(mb);
device.setFullScreenWindow(f);
}
}
Listener Code
public class Listeners
{
private class Listener_popup implements ActionListener
{
private Frame frame;
public Listener_popup(Frame f)
{
frame=f;
}
public void actionPerformed(ActionEvent e)
{
JDialog d= new JDialog(frame,"hello");
JLabel l=new JLabel("Hello");
d.add(l);
d.setSize(100,100);
d.setUndecorated(true);
d.setVisible(true);
}
}
}
I tried using a jButton with action listeners to create a jDialog and I looked into jPopup but it wasn't quite what I was looking for. Open to any suggestions.
I find it kind of weird that you're trying to display another window while your app is in "full screen exclusive" mode, the point is to give you window "exclusive" access to the screen device.
When I tried to display a
JOptionPaneon MacOS, nothing happened, but then I couldn't interact with the window, because the dialog had modal access :/.You could "fake" it though.
JOptionPaneis, after all, just a component.The following example makes use of the of the windows
glassPaneto present a customisedJOptionPane...Now, of you attached a
MouseListenerandKeyListenerto theglassPaneyou could effectively "consume" all of those events, making the dialog "appear" modal.