Solved

dialog recenters by itself

Posted on 1998-04-12
4
220 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 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

13 Experts available now in Live!

Get 1:1 Help Now