Change Display Mode in Swing

Total Views : 445
Zoom In Zoom Out Read Later Print

This code will help you to know how you can change the display mode and set custom resolution of the screen in Swing.

ChangeDisplayMode.java

package com.prodevsblog.how_to.swing;

import javax.swing.*;
import java.awt.*;

/**
 * Author Manjeet Verma
 * WebSite https://prodevsblog.com/
 */

public class ChangeDisplayMode {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setSize(800, 600);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        device.setFullScreenWindow(frame);
        device.setDisplayMode(new DisplayMode(800, 600, 32, 60));

        frame.setVisible(true);

        JButton btn = new JButton();
        btn.setText("Button");
        JPanel panel = new JPanel();

        panel.add(btn);
        frame.add(panel);

        btn.addActionListener(e->{
            JOptionPane.showMessageDialog(frame.getContentPane(), "JOptionPane");
        });
    }

}

Output of the code.

See More

Latest Photos