Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kamuara.reposync.window;
- import java.awt.Dialog;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.UIManager;
- public class SheetDialog
- {
- private JFrame _windowFrame;
- public static void main(String[] args)
- {
- System.setProperty("apple.awt.documentModalSheet", "true");
- System.setProperty("apple.awt.brushMetalLook", "true");
- try
- {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- new SheetDialog();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public SheetDialog()
- {
- _windowFrame = new JFrame();
- _windowFrame.setResizable(false);
- _windowFrame.setBounds(100, 100, 451, 320);
- _windowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- _windowFrame.getContentPane().setLayout(null);
- _windowFrame.setVisible(true);
- JButton showDialogButton = new JButton("Show Dialog");
- showDialogButton.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- showSheetDialog(_windowFrame, "Test", "This should be a sheet dialog", "Oke");
- }
- });
- showDialogButton.setBounds(328, 263, 117, 29);
- _windowFrame.getContentPane().add(showDialogButton);
- }
- public void showSheetDialog(JFrame owner, String title, String message, String button)
- {
- final JDialog messageDialog = new JDialog(owner, title, Dialog.ModalityType.DOCUMENT_MODAL);
- messageDialog.setBounds(30, 0, owner.getWidth() - 60, 130);
- // TODO: only when os is osx
- messageDialog.getRootPane().putClientProperty("apple.awt.documentModalSheet", "true");
- messageDialog.setLayout(null);
- int offsetX = 25;
- JLabel titleLabel = new JLabel(title);
- titleLabel.setFont(new Font("Lucida Grande", Font.BOLD, 13));
- titleLabel.setBounds(offsetX, 10, 100, 25);
- messageDialog.getContentPane().add(titleLabel);
- JLabel messageLabel = new JLabel(message);
- messageLabel.setVerticalTextPosition(JLabel.TOP);
- messageLabel.setHorizontalTextPosition(JLabel.LEFT);
- messageLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
- messageLabel.setBounds(offsetX, 10, messageDialog.getWidth()-10, messageDialog.getHeight()-60);
- messageDialog.getContentPane().add(messageLabel);
- JButton okButton = new JButton(button);
- okButton.setBounds(messageDialog.getWidth() - 105, messageDialog.getHeight() - 35, 100, 25);
- okButton.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent arg0)
- {
- messageDialog.dispose();
- }
- });
- messageDialog.getContentPane().add(okButton);
- messageDialog.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement