Cross Reference: SwingUtils.java
xref
: /
owl-s
/
src
/
org
/
mindswap
/
utils
/
SwingUtils.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
ronwalf
/*
2
ronwalf
* Created on Oct 30, 2004
2
ronwalf
*/
2
ronwalf
package
org
.
mindswap
.
utils
;
2
ronwalf
2
ronwalf
import
java
.
awt
.
Component
;
2
ronwalf
import
java
.
awt
.
Dimension
;
2
ronwalf
import
java
.
awt
.
Toolkit
;
2
ronwalf
import
java
.
awt
.
Window
;
2
ronwalf
import
java
.
awt
.
event
.
ActionEvent
;
2
ronwalf
import
java
.
awt
.
event
.
ActionListener
;
2
ronwalf
2
ronwalf
import
javax
.
swing
.
BoxLayout
;
2
ronwalf
import
javax
.
swing
.
JButton
;
2
ronwalf
import
javax
.
swing
.
JComponent
;
2
ronwalf
import
javax
.
swing
.
JFrame
;
2
ronwalf
import
javax
.
swing
.
JScrollPane
;
2
ronwalf
import
javax
.
swing
.
JTextArea
;
2
ronwalf
2
ronwalf
/**
2
ronwalf
*
@author
Evren Sirin
2
ronwalf
*/
2
ronwalf
public
class
SwingUtils
{
2
ronwalf
public
final
static
ActionListener
windowCloserAction
=
new
ActionListener
() {
2
ronwalf
public
void
actionPerformed
(
ActionEvent
e) {
2
ronwalf
JComponent
c = (
JComponent
) e.
getSource
();
2
ronwalf
Window
w = (
Window
) c.
getTopLevelAncestor
();
2
ronwalf
w.
dispose
();
2
ronwalf
}
2
ronwalf
};
2
ronwalf
2
ronwalf
public
static
void
centerFrame
(
Window
frame
) {
2
ronwalf
Dimension
screenSize
=
Toolkit
.
getDefaultToolkit
().
getScreenSize
();
2
ronwalf
Dimension
size
=
frame
.
getSize
();
2
ronwalf
screenSize
.
height
=
screenSize
.
height
/
2
;
2
ronwalf
screenSize
.
width
=
screenSize
.
width
/
2
;
2
ronwalf
size
.
height
=
size
.
height
/
2
;
2
ronwalf
size
.
width
=
size
.
width
/
2
;
2
ronwalf
int
y =
screenSize
.
height
-
size
.
height
;
2
ronwalf
int
x =
screenSize
.
width
-
size
.
width
;
2
ronwalf
2
ronwalf
frame
.
setLocation
(x, y);
2
ronwalf
}
2
ronwalf
2
ronwalf
2
ronwalf
public
static
void
showMessage
(
String
title
,
String
str
) {
2
ronwalf
JFrame
info
=
new
JFrame
(
title
);
2
ronwalf
JTextArea
t =
new
JTextArea
(
str
,
15
,
40
);
2
ronwalf
t.
setEditable
(
false
);
2
ronwalf
t.
setLineWrap
(
true
);
2
ronwalf
t.
setWrapStyleWord
(
true
);
2
ronwalf
JButton
ok
=
new
JButton
(
"Close"
);
2
ronwalf
ok
.
addActionListener
(
windowCloserAction
);
2
ronwalf
info
.
getContentPane
().
setLayout
(
new
BoxLayout
(
info
.
getContentPane
(),
BoxLayout
.
Y_AXIS
));
2
ronwalf
info
.
getContentPane
().
add
(
new
JScrollPane
(t));
2
ronwalf
info
.
getContentPane
().
add
(
ok
);
2
ronwalf
ok
.
setAlignmentX
(
Component
.
CENTER_ALIGNMENT
);
2
ronwalf
info
.
pack
();
2
ronwalf
//info.setResizable(false);
2
ronwalf
centerFrame
(
info
);
3
daenzerorama
//info.show();
3
daenzerorama
info
.
setVisible
(
true
);
2
ronwalf
}
2
ronwalf
}