Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Dialog Box

Posted on 2003-03-24
6
Medium Priority
?
196 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
  • 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
Technology Partners: 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

580 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