Solved

help

Posted on 2004-10-12
11
178 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the latest versions eclipse neon 2 139
create a gui in perl 3 71
recursion example 16 111
how do i compare an object based on two fields 6 49
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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.

911 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

24 Experts available now in Live!

Get 1:1 Help Now