Java Reference
In-Depth Information
* in a Preferences node that you pass in; we attach a ComponentListener to
* the Window.
*/
public
public static
static
void
void
monitorWindowPosition
(
final
final
Window w
,
final
final
Preferences pNode
) {
// Get the current saved position, if any
Point p
=
getSavedLocation
(
pNode
);
int
int
savedX
= (
int
int
)
p
.
getX
();
int
int
savedY
= (
int
int
)
p
.
getY
();
iif
(
savedX
!= -
1
) {
// Move window to is previous location
w
.
setLocation
(
savedX
,
savedY
);
}
else
else
{
// Not saved yet, at least make it look nice
centre
(
w
);
}
// Now make sure that if the user moves the window,
// we will save the new position.
w
.
addComponentListener
(
new
new
ComponentAdapter
() {
@Override
public
public
void
void
componentMoved
(
ComponentEvent e
) {
setSavedLocation
(
pNode
,
w
);
}
});
}
}
To use it after the relevant import, you can simply say, for example:
myFrame.pack( );
UtilGUI.centre(myFrame);
myFrame.setVisible(true);
Changing a Swing Program's Look and Feel
Problem
You want to change the look and feel of an application.