Problem with Full-screen mode
I've this code:
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 topPanel =new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel bottomPanel =new JPanel(new FlowLayout(FlowLayout.RIGHT));
//inserts into topPanel
JTextField textfield =new JTextField(20);
topPanel.add(textfield);
//inserts into bottomPanel
JButton exitButton =new JButton("Afslut");
bottomPanel.add(exitButton);
//inserts panels
win.add(topPanel, BorderLayout.NORTH);
win.add(bottomPanel, BorderLayout.SOUTH);
// Create a button 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);
}
});
try{
gs.setFullScreenWindow(win);
win.validate();
}catch (Exception ex){
System.out.println(ex);
}
}
}
It create a full-screen window with a JTextField and JButton to leave the program.
My problem is that I can't enter anything into my JTextField.
Hope somebody can help me.
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
JFrame frame = new JFrame(gs.getDefaultConfiguration());
//creating panels
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
//inserts into topPanel
JTextField textfield = new JTextField(20);
topPanel.add(textfield);
//inserts into bottomPanel
JButton exitButton = new JButton("Afslut");
bottomPanel.add(exitButton);
//inserts panels
frame.add(topPanel, BorderLayout.NORTH);
frame.add(bottomPanel, BorderLayout.SOUTH);
// Create a button 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);
}
});
gs.setFullScreenWindow(frame);
frame.setVisible(true);
}
}
> Well, when running your script, I don't get a
> full-screen window like my example-code. I just get a
> screen with maximum-size.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main
{
public static void main(String[] args)
{
// Create a window for full-screen mode; add a button to leave full-screen mode
JFrame frame = new JFrame();
//creating panels
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
//inserts into topPanel
JTextField textfield = new JTextField(20);
topPanel.add(textfield);
//inserts into bottomPanel
JButton exitButton = new JButton("Afslut");
bottomPanel.add(exitButton);
//inserts panels
frame.add(topPanel, BorderLayout.NORTH);
frame.add(bottomPanel, BorderLayout.SOUTH);
// Create a button 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.pack();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setVisible(true);
}
}
Alternatively u can get the screen size and set Jframe size according to it--
import javax.swing.*;
import java.awt.*;
public class FullScreen extends JFrame {
public FullScreen() {
this.setTitle("FullScreen");
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(d.width,d.height);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new FullScreen();
}
}