Solved

help

Posted on 2004-10-12
11
180 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
  • 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 200 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySqlDump not dumping triggers 1 43
how to install java on RHEL image on EC2 4 40
How  can  i  resolve  HTTP Status 404 -? 8 43
Setup GlassFish 4 21
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

856 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