?
Solved

Dialog Box

Posted on 2003-03-24
6
Medium Priority
?
192 Views
Last Modified: 2010-03-31
Hello,

I need to display a series of message boxes to a user.

I have founf the following code...


Dialog(Frame owner, String title, boolean modal);
i.e.
Dialog mydialog = new Dialog(myWindowFrame,"My Dialog",true);

then do the layout of the dialog i.e. add messages, buttons etc.
Panel p= new Panel(new FlowLayout());
p.add(new Label("Hello, I am mgFranz"));
then say:
myDialog.add(p);
myDialog.show();

What is the Frame Owner? and how can I display an OK button on the dialog?

Regards
john
0
Comment
Question by:jjcrook
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:FaithNoMore
ID: 8199263
I think this is what you want, you can play around with the size of the TA/Dialog to get the desired look.

public class myDialog extends Dialog
{

  TextArea TA = new TextArea(5, 50);
  Button Ok = new Button("Ok");

  public myDialog(Frame frame, String msg, boolean mod)
  {
    super(frame, "My Dialog Title");    
    setLayout(new Flowlayout());
    TA.setText(msg);  // Sets you message.
    add(TA);
    add(Ok);
    setSize(200, 300);
    setVisibilty(true);  
  }

}
0
 
LVL 1

Expert Comment

by:FaithNoMore
ID: 8199266
You can add a "setModal(mod);" to make it Modal.
0
 
LVL 1

Accepted Solution

by:
FaithNoMore earned 50 total points
ID: 8199308
Oh yeh... The Frame Owner is the frame that called the dialog.  Usually Dialogs are used to display messages/errors.  Lets say on your main frame the user clicks on a button that causes a dialog to appear you would do the follow:

new MyDialog(this, "You triggered me", true);


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jjcrook
ID: 8202439
How can I make the OK button close the dialog box?
0
 
LVL 1

Expert Comment

by:FaithNoMore
ID: 8202862
This is the code for my dialog box (JDialog is very similar to Dialog).  The FlowLayout makes the OK Button close to the TextArea, its just the way this layout works.

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

public class ERRDIALOG extends JDialog implements ActionListener
{
  JTextArea TA = new JTextArea();
  JButton OK = new JButton("Ok");
  Container content;

  public ERRDIALOG(JFrame frame, String err){
    super(frame, "Error", true);
    content = getContentPane();
    setSize(350, 200);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    TA.setText(err);
    setResizable(false);
    init();
    setVisible(true);
  }

  private void init()
  {
      TA.setPreferredSize(new Dimension(320, 100));
      OK.setPreferredSize(new Dimension(100, 30));
      content.setLayout(new FlowLayout(FlowLayout.CENTER, 5,10));
      content.add(TA);
      content.add(OK);
      TA.setEditable(false);
      TA.setFont(new java.awt.Font("SansSerif", 1, 14));
      OK.addActionListener(this);
  }


  public void actionPerformed(ActionEvent e){
    if(e.getSource() == OK) dispose();
  }
0
 

Author Comment

by:jjcrook
ID: 8202945
That's superb!

Thank you very much.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question