Java Reference
In-Depth Information
cp
.
add
(
top
,
BorderLayout
.
NORTH
);
JPanel attrs
=
new
new
JPanel
();
top
.
add
(
attrs
);
attrs
.
setLayout
(
new
new
GridLayout
(
0
,
1
));
attrs
.
add
(
bold
=
new
new
JCheckBox
(
"Bold"
,
false
false
));
attrs
.
add
(
italic
=
new
new
JCheckBox
(
"Italic"
,
false
false
));
// Make sure that any change to the GUI will trigger a font preview.
ListSelectionListener waker
=
new
new
ListSelectionListener
() {
public
public
void
void
valueChanged
(
ListSelectionEvent e
) {
previewFont
();
}
};
fontSizeChoice
.
addListSelectionListener
(
waker
);
fontNameChoice
.
addListSelectionListener
(
waker
);
ItemListener waker2
=
new
new
ItemListener
() {
public
public
void
void
itemStateChanged
(
ItemEvent e
) {
previewFont
();
}
};
bold
.
addItemListener
(
waker2
);
italic
.
addItemListener
(
waker2
);
previewArea
=
new
new
JLabel
(
displayText
,
JLabel
.
CENTER
);
previewArea
.
setSize
(
200
,
50
);
cp
.
add
(
previewArea
,
BorderLayout
.
CENTER
);
JPanel bot
=
new
new
JPanel
();
JButton okButton
=
new
new
JButton
(
"Apply"
);
bot
.
add
(
okButton
);
okButton
.
addActionListener
(
new
new
ActionListener
() {
public
public
void
void
actionPerformed
(
ActionEvent e
) {
previewFont
();
dispose
();
setVisible
(
false
false
);
}
});
JButton canButton
=
new
new
JButton
(
"Cancel"
);
bot
.
add
(
canButton
);
canButton
.
addActionListener
(
new
new
ActionListener
() {
public
public
void
void
actionPerformed
(
ActionEvent e
) {
// Set all values to null. Better: restore previous.