[4489] in java-interest
Help with Dialog boxes
daemon@ATHENA.MIT.EDU (Kevin Conner)
Tue Jan 2 21:26:13 1996
Date: Tue, 2 Jan 96 12:43:42 GMT
From: knrc@impmh.uucp@sun.com (Kevin Conner)
To: java-interest@java.Eng.Sun.COM
I have been playing about with the prebeta java for stand alone
applications and have a problem with extending Dialogs.
In one of my noddy programs I wanted to create a Dialog which
would display an error message and an OK button, for no other
reason than to try using Dialogs.
My constructor creates a Label and a button, tries to resize
them according to the font being used and then calls pack to
get the Dialog resized with the preferred size of each
component. When my dialog is shown the Dialog window is smaller
than is required to display both the label and button.
I spent some time going through this and discovered that the
preferredLayoutSize and layoutContainer methods in BorderLayout
were getting the value (0,0,0,0) for insets instead of (25,5,5,5).
According to the source code for BorderLayout the insets should be
coming from the target and that the target's Container asks the
ContainerPeer for the insets.
jdb shows
Breakpoint hit: java.awt.BorderLayout.preferredLayoutSize
target = MyDialog[0,0,11x31,invalid,hidden,layout=java.awt.BorderLayout,modal,title=Error Dialog]
dump target
ComponentPeer peer = (sun.awt.motif.MDialogPeer)0xee305f38
dump 0xee305f38
Insets insets = (java.awt.Insets)0xee305f40
dump 0xee305f40
0xee305f40 = (java.awt.Insets)0xee305f40 {
public int top = 25
public int left = 5
public int bottom = 5
public int right = 5
}
Given that the peer exists and that it has nonzero insets why
am I getting a return value of (0,0,0,0) from target.insets()?
I added calls to list() and they showed the following
MyDialog[0,0,99x40,hidden,layout=java.awt.BorderLayout,modal,title=Error Dialog]
java.awt.Label[0,0,99x20,align=center,label=File Access Error]
java.awt.Button[0,20,99x20,label=OK]
but xwininfo shows the geometry of the Dialog as 89x10, i.e. the
preferredSize minus the insets. If the window is resized then
the second list still shows the same difference.
Have I missed something here?
Thanks in advance,
Kev
P.S. Here is the code for my version of a Dialog.
class MyDialog extends Dialog {
MyDialog(Frame parent, boolean modal, String errormsg)
{
this(parent, "Error Dialog", modal, errormsg) ;
}
MyDialog(Frame parent, String title, boolean modal, String errormsg)
{
super(parent, title, modal) ;
Label myLabel = new Label(errormsg, Label.CENTER) ;
Graphics gc = parent.getGraphics() ;
FontMetrics fm = gc.getFontMetrics() ;
myLabel.resize(fm.stringWidth(errormsg), fm.getHeight()) ;
add("North", myLabel) ;
Button mybutton = new Button("OK") ;
mybutton.resize(fm.stringWidth(mybutton.getLabel()), fm.getHeight()) ;
add("South", mybutton) ;
pack() ;
list() ;
}
public boolean action(Event evt, Object what)
{
if ("OK".equals(evt.arg))
{
list() ;
dispose() ;
return true ;
}
return false ;
}
}
------------------------------------------------------------------------------
Kevin Conner knrc@impltd.com Integrated Micro Products
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com