Advertisement
Guest User

SheetDialog

a guest
Jul 25th, 2013
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. package com.kamuara.reposync.window;
  2.  
  3. import java.awt.Dialog;
  4. import java.awt.Font;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JDialog;
  10. import javax.swing.JFrame;
  11. import javax.swing.JLabel;
  12. import javax.swing.UIManager;
  13.  
  14. public class SheetDialog
  15. {
  16.     private JFrame _windowFrame;
  17.    
  18.     public static void main(String[] args)
  19.     {
  20.         System.setProperty("apple.awt.documentModalSheet", "true");
  21.         System.setProperty("apple.awt.brushMetalLook", "true");
  22.        
  23.         try
  24.         {
  25.             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  26.            
  27.             new SheetDialog();
  28.         }
  29.         catch (Exception e)
  30.         {
  31.             e.printStackTrace();
  32.         }
  33.     }
  34.    
  35.     public SheetDialog()
  36.     {
  37.         _windowFrame = new JFrame();
  38.         _windowFrame.setResizable(false);
  39.         _windowFrame.setBounds(100, 100, 451, 320);
  40.         _windowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  41.         _windowFrame.getContentPane().setLayout(null);
  42.         _windowFrame.setVisible(true);
  43.        
  44.         JButton showDialogButton = new JButton("Show Dialog");
  45.         showDialogButton.addActionListener(new ActionListener()
  46.         {
  47.             @Override
  48.             public void actionPerformed(ActionEvent e)
  49.             {
  50.                 showSheetDialog(_windowFrame, "Test", "This should be a sheet dialog", "Oke");
  51.             }
  52.         });
  53.         showDialogButton.setBounds(328, 263, 117, 29);
  54.         _windowFrame.getContentPane().add(showDialogButton);
  55.     }
  56.    
  57.     public void showSheetDialog(JFrame owner, String title, String message, String button)
  58.     {
  59.         final JDialog messageDialog = new JDialog(owner, title, Dialog.ModalityType.DOCUMENT_MODAL);
  60.         messageDialog.setBounds(30, 0, owner.getWidth() - 60, 130);
  61.        
  62.         // TODO: only when os is osx
  63.         messageDialog.getRootPane().putClientProperty("apple.awt.documentModalSheet", "true");
  64.         messageDialog.setLayout(null);
  65.        
  66.         int offsetX = 25;
  67.  
  68.         JLabel titleLabel = new JLabel(title);
  69.         titleLabel.setFont(new Font("Lucida Grande", Font.BOLD, 13));
  70.         titleLabel.setBounds(offsetX, 10, 100, 25);
  71.         messageDialog.getContentPane().add(titleLabel);
  72.        
  73.         JLabel messageLabel = new JLabel(message);
  74.         messageLabel.setVerticalTextPosition(JLabel.TOP);
  75.         messageLabel.setHorizontalTextPosition(JLabel.LEFT);
  76.         messageLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
  77.         messageLabel.setBounds(offsetX, 10, messageDialog.getWidth()-10, messageDialog.getHeight()-60);
  78.         messageDialog.getContentPane().add(messageLabel);
  79.        
  80.         JButton okButton = new JButton(button);
  81.         okButton.setBounds(messageDialog.getWidth() - 105, messageDialog.getHeight() - 35, 100, 25);
  82.         okButton.addActionListener(new ActionListener()
  83.         {
  84.             @Override
  85.             public void actionPerformed(ActionEvent arg0)
  86.             {
  87.                 messageDialog.dispose();
  88.             }
  89.         });
  90.         messageDialog.getContentPane().add(okButton);
  91.        
  92.         messageDialog.setVisible(true);
  93.     }
  94.    
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement