create Dialog - Java Swing

Java examples for Swing:JOptionPane

Description

create Dialog

Demo Code


//package com.java2s;
import java.awt.Dialog;
import java.awt.Toolkit;
import javax.swing.JDialog;
import javax.swing.JTextField;

public class Main {
    public static Dialog createDialog(String title, String message) {
        Dialog dialog = new JDialog();

        dialog.setName(title);//ww  w . ja v  a2 s .c o m
        dialog.setTitle(title);

        JTextField messageField = new JTextField(message);
        messageField.setEditable(false);

        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
        int height = Toolkit.getDefaultToolkit().getScreenSize().height;

        int dialogWidth = (message.length() * 6) + 25;
        int dialogHeight = 100;

        dialog.setBounds((width / 2) - (dialogWidth / 2), (height / 2)
                - (dialogHeight / 2), dialogWidth, dialogHeight);

        dialog.setResizable(false);

        dialog.add(messageField);

        return dialog;
    }
}

Related Tutorials