-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
generic
-
generic
Name: boT120536 Date: 12/06/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
Since Java 1.2 the AWT Dialog has had a number of problems evident when run
on Linux under the fvwm2 window manager.
If setLocation is used for positioning of either the Dialog or its
parent Frame, the content of the Dialog is often offset and the Dialog
size is set too small. JDK 1.3 does not fix the problem. It does not
appear on the Windows or the Solaris versions of Java.
I do not know of any way to reliably deal with the problem, which is
demonstrated with the example program below. It seems to be caused by
the internal use of getInsets(), which is unreliable. When I have
called this after successive displays of the Dialog, I have got
different numbers, including occasionally negative ones. The version of
the example given below reports
Insets 0,0,0,0
in the first call to showDialog(), and
Insets 14,14,62,14
subsequently. When the same program is run on our Solaris sparc machine
and displays in a window under fvwm2 on my Linux box, the insets reported
are
Insets 5,5,25,5
after the first call, and
Insets 5,5,23,5
subsequently, even though the hardware and window manager for the window
display are identical.
The Linux execution of this program causes most of the content of the dialog
to be unreadable. A copy of this initial window can be seen at
http://www.cs.adfa.edu.au/~gfreeman/dialog.window.gif
and the subsequent display can be seen at
http://www.cs.adfa.edu.au/~gfreeman/dialog.window2.gif
In another example where the MFrame instance is created from a separate
interface, the window has a sensible size but is only partially drawn
http://www.cs.adfa.edu.au/~gfreeman/dialog.window3.gif
and the insets are reported as
Insets 2,2,2,2
If the window is given an X-Windows Expose event by covering and uncovering
with another window, it is still only partially drawn.
If the MFrame program is invoked on my Linux box from a Netscape browser
running the default 1.1 Java virtual machine, MFrame works perfectly.
The problem has been introduced at JDK 1.2 and persists in 1.3.
After the Dialog is displayed the second time, the content is not usually
misplaced, so the problem can be partly avoided with code like:
private boolean firstdone = false; // in the class
and in the code to display the Dialog:
if (!firstdone)
{
setModal(false);
show();
dispose();
pack();
show();
dispose();
firstdone = true;
setModal(true);
}
show();
(Yes, two extra calls to show/dispose seem to be required, along with a
pack!)
Even with these changes, there can still be problems with Dialog size.
If there are several Dialogs as part of the one interface, there seems
to be an interaction between them that causes the size of them to change
when they are repeatedly displayed alternately. Sometimes, they grow in
size; others diminish in size. It looks as if Insets is the culprit, but
I do not have a simple enough example that demonstrates the fault
conclusively.
I have also observed that if the mis-sized dialog is visible, I can use
the window manager to resize it. If it has been specified as
setResizable(false), attempting to resize causes the window to
immediately jump to its correct size.
I posted this problem to the Java programmers newsgroup, and have
received confirmation from Bernd Eggink (###@###.###)
that the problem also exists with the Swing JDialog:
> I encounter similar problems under Linux with Swing. The JDialogs show
> up at random places with sizes varying between zero and infinity,
> completely ignoring any setBounds() parameters. 1.2.2 has been buggy in
> this respect already, but in 1.3 the situation is really unbearable.
Graham Freeman
----------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
public class MFrame extends Frame
{
protected DialogAddr dprt;
protected Button but1, quit;
/***************************************************************************
* Construct a frame for displaying a Dialog.
***************************************************************************/
public MFrame()
{
// set frame properties
setTitle("Test Dialog display");
setBackground(Color.getHSBColor(0.28F,0.2F,0.75F));
Font fs14 = new Font("Serif",Font.PLAIN,14);
setFont(fs14);
setLayout( new FlowLayout() );
but1 = new Button("Show dialog");
quit = new Button("Quit");
add(but1);
add(quit);
but1.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
String reply = dprt.showDialog();
if (reply != null) System.out.println(reply);
}
}
);
quit.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
System.exit(0);
}
}
);
pack();
}
/***************************************************************************
* Create the Dialogs used by MFrame.
***************************************************************************/
public void mfInit()
{
dprt = new DialogAddr(this);
// dprt.setResizable(false); //Uncomment when it all works properly
}
/***************************************************************************
* Main program to run MFrame.
***************************************************************************/
public static void main(String[] args)
{
MFrame q = new MFrame();
q.mfInit();
q.setLocation( 50, 50); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
q.show();
}
/*************************************************************************
* Handle the interaction with the user.
*************************************************************************/
class DialogAddr extends Dialog
implements ActionListener, TextListener
{
protected TextField fromPage;
private boolean ok;
private boolean firstdone = false;
/*********************************************************************
* Construct a dialog.
*
* @param parent The Frame to which the class belongs.
*********************************************************************/
public DialogAddr( Frame parent )
{
// super(parent,"Reply address",true);
// Modal is wanted, but start with non-modal
super(parent,"Reply address",false);
Font fs14 = new Font("Serif",Font.PLAIN,14);
setFont(fs14);
setBackground(new Color(0,168,168));
setLayout( new FlowLayout() );
add(new Label(" From: "));
fromPage = new TextField("1",50);
fromPage.addTextListener( this );
add( fromPage );
Button bok = new Button("Ok");
add(bok);
bok.addActionListener(this);
Button bcl = new Button("Cancel");
add(bcl);
bcl.addActionListener(this);
validate();
pack();
}
/**********************************************************************
* Remove the DialogAddr when a button is pressed, setting "ok" state.
*
* @param evt the ActionEvent.
**********************************************************************/
public void actionPerformed(ActionEvent evt)
{
String s = evt.getActionCommand();
if (s.equals("Ok"))
ok = true;
dispose();
}
/**********************************************************************
* Text has been received.
**********************************************************************/
public void textValueChanged(TextEvent evt)
{
//do nothing at present
}
/**********************************************************************
* Show the DialogAddr and obtain message typed in the field.
*
* @return The message.
**********************************************************************/
public String showDialog()
{
String s = null;
Point pt = getParent().getLocation();
setLocation(pt.x+10,pt.y+40); //<<<<<<<<<<<<<<<<<<<<<<<<<<
ok = false;
fromPage.setText("Your e-mail address");
pack(); // for subsequent calls
Insets ins = getInsets();
System.err.println("Insets "+ins.left+","+ins.right+
","+ins.top+","+ins.bottom);
// if (!firstdone)
// {
// show();
// ins = getInsets();
// System.err.println("Insets "+ins.left+","+ins.right+
// ","+ins.top+","+ins.bottom);
// dispose();
// pack();
// show();
// ins = getInsets();
// System.err.println("Insets "+ins.left+","+ins.right+
// ","+ins.top+","+ins.bottom);
// dispose();
// firstdone = true;
// setModal(true);
// }
show();
if (ok)
{
s = (fromPage.getText().trim());
}
return s;
}
}
}
// When run on Linux under fvwm2, the Dialog has incorrect size on first
// display, but subsequently comes up correctly. The problem can be
// fixed by uncommenting the "firstdone" code in showDialog. Alternatively,
// if the two calls to setLocation are commented out, again it works properly.
(Review ID: 112736)
======================================================================
- duplicates
-
JDK-4493724 With eXceed only the left-hand quarter of a window repainted
-
- Resolved
-