Solved

dialog recenters by itself

Posted on 1998-04-12
4
222 Views
Last Modified: 2010-04-16
I have a dialog that I hide and show a few times, I am referring to one dialog object.
When run under one JVM (Symantec Cafe), the dialog stays positioned where it was before
it was previously hidden. I like it that way.
When run under Sun's JVM or Netscape, the dialog is recentered on its parent every time it
is reshown.

Is there a simple way I can overcome this (except saving coordinates and moving the dialog by
myself) ?
0
Comment
Question by:mco
  • 2
4 Comments
 

Expert Comment

by:mparekh
ID: 1234048
when you are creating the dialog, it depends on the parent frame where it is positioned.
If you are passing the current frame pointer, then it will always open up at the centre of the parent frame.
Rather the center of the Frame and the center of the dialog
co-incide. So maybe Symantec's JVM has a bug. The way sun's JVM behaves is the right way.
0
 
LVL 1

Author Comment

by:mco
ID: 1234049
You are right with regard to CREATION, but I am referring to re-showing, i.e. calling
setVisible(false), and then setVisible(true).
BTW, I checked more carefully:, Sun's JVM behaves like this on Solaris, but Sun's
JVM on W95 behaves as I expect (the dialog stays where it was).

0
 
LVL 4

Accepted Solution

by:
evijay earned 150 total points
ID: 1234050
Hi,

I am using jdk1.1.6 (now available for download from sun site) and i didnt face this problem. I am giving you a sample test program. This program displays a push button. When you click on it, it displays a dialog. move the dialog at what ever place you want and press close button on the dialog. Then again if you press the "push" button on main frame the dialog reappears in the same position as earlier. I am using show and hide for this purpose.

import java.awt.*;
import java.awt.event.*;
public class TestDialog extends Frame {
      Dialog dlg;
      TestDialog()
      {
            super("Testing dialogs");
            setLayout(new FlowLayout());
            Button b = new Button("Push Me");
             add(b);
            b.addActionListener(
                  new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
                            if (dlg == null) {
                              dlg = createModalDialog();
                            }
                              dlg.setVisible(true);
                        }
                  }
            );
            b = new Button("Exit");
             add(b);
            b.addActionListener(
                  new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
                              System.exit(1);
                        }
                  }
            );
            setSize(200, 200);
            addWindowListener(
                new WindowAdapter() {
                  public void windowClosing(WindowEvent e)
                  {
                        System.exit(1);
                  }
                }
            );
      }
      public void hideDialog(Component src)
      {
            for (Component parent = src;
                        parent != null; parent = parent.getParent()) {
                  if (parent instanceof Dialog) {
                        parent.setVisible(false);
//                        ((Dialog)parent).dispose();
                        break;
                  }
            }
      
      }

      private Dialog createModalDialog()
      {
            Dialog dialog = new Dialog(this, "TestDialog1", true);
            dialog.setSize(400, 400);
            Panel mainPanel = new Panel();
            mainPanel.setLayout(new BorderLayout());
            Panel contentPanel = new Panel();
            contentPanel.setLayout(new GridLayout(4, 2));
            contentPanel.add(new Label("Label1 : "));
            contentPanel.add(new TextField());
            contentPanel.add(new Label("Label2 : "));
            contentPanel.add(new TextField());
            contentPanel.add(new Label("Label3 : "));
            contentPanel.add(new Button("Button1"));
            contentPanel.add(new Label("Label4 : "));
            contentPanel.add(new Button("Button1"));

            mainPanel.add("Center", contentPanel);
            Button b2 = new Button ("Close");
            b2.addActionListener(
                  new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
                              hideDialog((Component) e.getSource());
                        }
                  }      
            );

            Panel buttonPanel = new Panel();
            FlowLayout fl;
            buttonPanel.setLayout(fl = new FlowLayout());
            fl.setAlignment(FlowLayout.CENTER);
            buttonPanel.add(b2);
            mainPanel.add("South", buttonPanel);
            dialog.add(mainPanel);
            dialog.addWindowListener(
                new WindowAdapter() {
                  public void windowClosing(WindowEvent e)
                  {
                              hideDialog((Component) e.getSource());
                  }
                }
            );
            return dialog;
      }
                              
      public static void main(String args[])
      {
            new TestDialog().setVisible(true);

      }
}


0
 
LVL 4

Expert Comment

by:evijay
ID: 1234051
So the problem is only on Solaris platform?

What window manager do you use? Don't forget that some window managers on Unix systems override the windows' locations on the screen to do a "wise" windows displaying. This is especially true with FVWM (I, II and 95). However, there is a way to set this functionality OFF on the config file of the window manager.

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
splitOdd10 challenge 5 80
base64 decode encode 12 119
Java - sorting a list of objects where the properties of the objects can change during the sort 7 47
diffSum example 4 24
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

910 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

20 Experts available now in Live!

Get 1:1 Help Now