Modal Message Dialog : Dialog « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing JFC » DialogScreenshots 
Modal Message Dialog
   
/*
This file is part of BORG.

    BORG is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    BORG is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with BORG; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Copyright 2003 by Mike Berger
*/
/*
 * helpscrn.java
 *
 * Created on October 5, 2003, 8:55 AM
 */


import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;




public class ModalMessage extends JDialog {
 
    public ModalMessage(String s, boolean enabled) {
        initComponents();    
        jTextArea.setText(s);
        okButton.setEnabled(enabled);
        setModal(true);       
    }

    public void setEnabled(boolean e)
    {
      okButton.setEnabled(e);
    }
    public void setText(String s)
    {
      jTextArea.setText(s);
    }
    
    public void appendText(String s)
    {
      String t = jTextArea.getText();
      t += "\n" + s;
      jTextArea.setText(t);
    }
    
    private void initComponents()//GEN-BEGIN:initComponents
    {
      //this.setUndecorated(true);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        setTitle("BORG");
        this.setSize(165300);
        this.setContentPane(getJPanel());
        
        pack();
        
        Dimension screenSize =
            Toolkit.getDefaultToolkit().getScreenSize();
          Dimension labelSize = jScrollPane.getPreferredSize();
          setLocation(screenSize.width/(labelSize.width/2),
                      screenSize.height/(labelSize.height/2));
    }
    
    
    private JPanel jPanel = null;
  private JScrollPane jScrollPane = null;
  private JTextArea jTextArea = null;
  
  /**
   * This method initializes jPanel 
   *  
   @return javax.swing.JPanel 
   */
  private JPanel getJPanel() {
    if (jPanel == null) {
      GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
      gridBagConstraints1.gridx = 0;  // Generated
      gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;  // Generated
      gridBagConstraints1.gridy = 1;  // Generated
      GridBagConstraints gridBagConstraints = new GridBagConstraints();
      gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;  // Generated
      gridBagConstraints.gridy = 0;  // Generated
      gridBagConstraints.weightx = 1.0;  // Generated
      gridBagConstraints.weighty = 1.0;  // Generated
      gridBagConstraints.insets = new java.awt.Insets(4,4,4,4);  // Generated
      gridBagConstraints.gridx = 0;  // Generated
      jPanel = new JPanel();
      jPanel.setLayout(new GridBagLayout());  // Generated
      jPanel.add(getJScrollPane(), gridBagConstraints);  // Generated
      jPanel.add(getButtonPanel(), gridBagConstraints1);
    }
    return jPanel;
  }



  /**
   * This method initializes jScrollPane  
   *  
   @return javax.swing.JScrollPane  
   */
  private JScrollPane getJScrollPane() {
    if (jScrollPane == null) {
      jScrollPane = new JScrollPane();
      jScrollPane.setPreferredSize(new java.awt.Dimension(600,200));  // Generated
      jScrollPane.setViewportView(getJTextArea());  // Generated
    }
    return jScrollPane;
  }



  /**
   * This method initializes jTextArea  
   *  
   @return javax.swing.JTextArea  
   */
  private JTextArea getJTextArea() {
    if (jTextArea == null) {
      jTextArea = new JTextArea();
      jTextArea.setEditable(false);  // Generated
      jTextArea.setLineWrap(true);  // Generated
    }
    return jTextArea;
  }

  /**
   * This method initializes buttonPanel  
   *  
   @return javax.swing.JPanel 
   */
  private JPanel buttonPanel = null;
  private JPanel getButtonPanel() {
    if (buttonPanel == null) {
      buttonPanel = new JPanel();
      buttonPanel.add(getOkButton()null);  // Generated
      
    }
    return buttonPanel;
  }



  /**
   * This method initializes okButton 
   *  
   @return javax.swing.JButton  
   */
  private JButton okButton = null;
  private JButton getOkButton() {
    if (okButton == null) {
      okButton = new JButton();
      okButton.setText("OK");
      okButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          doOk();
        }
      });
    }
    return okButton;
  }

  private void doOk()
  {
    this.dispose();
  }


  public static void mainString args[])
    {
    final ModalMessage mm = new ModalMessage("duh\nduh\nduh"false);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
          mm.setVisible(true);        
      }
    });
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
          mm.appendText("another line");
          mm.setEnabled(true);        
      }
    });
      
    }
}  //  @jve:decl-index=0:visual-constraint="10,10"

   
    
    
  
Related examples in the same category
1. Creating and using Dialog BoxesCreating and using Dialog Boxes
2. Dialog boxes and creating your own componentsDialog boxes and creating your own components
3. A frame that can easily support internal frame dialogsA frame that can easily support internal frame dialogs
4. An example of using the JOptionPane with a custom list of options in anAn example of using the JOptionPane with a custom list of options in an
5. See the differences between various types of option panesSee the differences between various types of option panes
6. Vote DialogVote Dialog
7. Create simple about dialogCreate simple about dialog
8. Dialog separatorDialog separator
9. Message dialogMessage dialog
10. Error message dialogError message dialog
11. Information dialog with customized logoInformation dialog with customized logo
12. Input dialog with user-defined logoInput dialog with user-defined logo
13. Confirmation dialogConfirmation dialog
14. Default button for dialog: press Enter to activateDefault button for dialog: press Enter to activate
15. Simple dialog for asking a yes no questionSimple dialog for asking a yes no question
16. Class to Prompt the User for an ID and Password
17. Simple Save Dialog demoSimple Save Dialog demo
18. Demonstrate JOptionPaneDemonstrate JOptionPane
19. Create Color Sample PopupCreate Color Sample Popup
20. Simple Input DialogSimple Input Dialog
21. No button dialogNo button dialog
22. Message Dialog demo Message Dialog demo
23. Escape Key close Dialog
24. Dialog can be closed by pressing the escape key
25. Dialog which displays indeterminate progress
26. Dialog with Escape KeyDialog with Escape Key
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.