Solved

help

Posted on 2004-10-12
11
177 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now