at.spardat.xma.boot.DetailsDialog Maven / Gradle / Ivy
package at.spardat.xma.boot;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
class DetailsDialog extends JDialog implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 8688703111882816444L;
/**
* Constructor of the details dialog.
*
* Creates a dialog with a text area.
*/
public DetailsDialog(String title, String detailText) {
/* Title */
setTitle(title);
/* Size, location and layout */
setSize(750, 550);
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final Dimension screenSize = toolkit.getScreenSize();
final int x = (screenSize.width - getWidth()) / 2;
final int y = (screenSize.height - getHeight()) / 2;
setLocation(x, y);
setBackground(Color.gray);
getContentPane().setLayout(new BorderLayout());
/* Create controls */
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel, BorderLayout.CENTER);
JTextArea area = new JTextArea();
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().add(area);
scrollPane.setBounds(10, 10, 280, 180);
topPanel.add(scrollPane, BorderLayout.CENTER);
JPanel actionPane = new JPanel();
topPanel.add(actionPane,BorderLayout.PAGE_END);
JButton closeButton = new JButton("Close");
closeButton.setVerticalTextPosition(AbstractButton.BOTTOM);
closeButton.setHorizontalTextPosition(AbstractButton.CENTER);
closeButton.addActionListener(this);
closeButton.setActionCommand("close");
actionPane.add(closeButton);
/* Detail text */
area.setText(detailText);
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if ("close".equals(e.getActionCommand())) {
setVisible(false);
dispose();
}
}
/**
* Test
* @param args
*/
public static void main(String args[]) {
DetailsDialog dialog = new DetailsDialog("Details dialog","This is the detail text.\nIs has 2 lines.");
dialog.setVisible(true);
}
}