?
Solved

help

Posted on 2004-10-12
11
Medium Priority
?
183 Views
Last Modified: 2010-03-31
hi experts..
I want to select a menuItem that say "About" and get a small frame or dialog box that will have a couple lines of information like copyright and name of program. Do I just do that with a fram or what?
0
Comment
Question by:Samooramad
[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
  • 6
  • 5
11 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12286895
I'd use a modal JDialog and add in it's root pane a panel containing whatever info you want.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 800 total points
ID: 12287217
I meant "its content pane" instead of root pane

(Excuse me I reused the same "frame" again ;°)

/*
 * JOptionPaneDemo2.java
 *
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
 *
 * @author  zzynx
 */
public class JOptionPaneDemo2 extends JFrame {
   
    public JOptionPaneDemo2() {
        init();
        setSize(500, 400);
        setLocationRelativeTo(null);
    }

    private void init() {
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                System.exit(0);
            }
        });
       
        JButton button2 = new JButton("About");
        button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button2ActionPerformed(evt);
            }
        });
       
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(button2);
       
        pack();
    }
   
    private void button2ActionPerformed(java.awt.event.ActionEvent evt) {
        JPanel aboutPanel = new JPanel();
        JLabel lbl = new JLabel("Put here whatever you want...");
        aboutPanel.add(lbl);
        JLabel lbl2 = new JLabel("Put here whatever you want...(bis)");
        aboutPanel.add(lbl2);
       
        JDialog dlg = new JDialog(this, true);
        dlg.getContentPane().add(aboutPanel);
        dlg.setSize( new Dimension(200, 200));
        dlg.setLocationRelativeTo(this);
        dlg.show();
    }
   
    public static void main(String args[]) {
        JOptionPaneDemo2 f = new JOptionPaneDemo2();
        f.show();
    }
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12287236
Remark: I used a button to trigger instead of a menu, but that's irrelevant for your question, isn't it?
0
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.

 

Author Comment

by:Samooramad
ID: 12287855
well I guess :)
ok I'll get back to you
0
 

Author Comment

by:Samooramad
ID: 12288010
yeah worked great..I'll award points now but could you tell me what this and true do in:
    JDialog dlg = new JDialog(this, true);

thanks
0
 

Author Comment

by:Samooramad
ID: 12288035
also what does setModal do?
0
 

Author Comment

by:Samooramad
ID: 12288054
one more :)
where exactly does   dlg.setLocationRelativeTo(this); place the dialog box?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12288130
>> JDialog dlg = new JDialog(this, true);
-this passes the main JFrame (the instance of JOptionPaneDemo2) as the owner of the dialog.
-true means: modal

>>also what does setModal do?
Where do you see that in the code?

>>where exactly does   dlg.setLocationRelativeTo(this); place the dialog box?
In the middle of "this" being "the instance of JOptionPaneDemo2", your main frame


0
 
LVL 37

Expert Comment

by:zzynx
ID: 12288161
>>where exactly does   dlg.setLocationRelativeTo(this); place the dialog box?
If you like to have it *always* in the middle of the screen (no matter where your frame is) then pass null as parameter:

       dlg.setLocationRelativeTo(null);
0
 

Author Comment

by:Samooramad
ID: 12290123
>>Where do you see that in the code?
not in your code ..I saw it somewhere else and thought I'd ask
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12290835
setModal() specifies whether this dialog should be ... modal  (surprise !!! :°)
0

Featured Post

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!

Question has a verified solution.

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

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 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