Solved

help

Posted on 2004-10-12
11
181 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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
servlet filter example 37 85
jsp login check 12 53
What's wrong with this code? 4 36
junit as external jar or library 7 40
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

726 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