UIUtil.jGridBagAdd(sizePanel, new JLabel("Size:"), gBC3, GridBagConstraints.REMAINDER);
UIUtil.jGridBagAdd(sizePanel, fontSize = new JFormattedTextField(new Integer(4)), gBC3, GridBagConstraints.REMAINDER);
fontSize.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
if (!sizeIsAdjusting)
changeFontBasedOnState();
}
public void removeUpdate(DocumentEvent e) {
if (!sizeIsAdjusting)
changeFontBasedOnState();
}
public void changedUpdate(DocumentEvent e) {
if (!sizeIsAdjusting)
changeFontBasedOnState();
}
});
gBC3.weighty = 1.0;
UIUtil.jGridBagAdd(sizePanel, new JScrollPane(fontSizeList), gBC3, GridBagConstraints.REMAINDER);
}
// Create the panel where selection of the font name takes place
JPanel namePanel = new JPanel(new GridBagLayout());
namePanel.setBorder(BorderFactory.createTitledBorder("Font name"));
GridBagConstraints gBC2 = new GridBagConstraints();
gBC2.fill = GridBagConstraints.BOTH;
gBC2.anchor = GridBagConstraints.WEST;
gBC2.weightx = 1.0;
gBC2.weighty = 0.0;
gBC2.insets = new Insets(2, 2, 2, 2);
UIUtil.jGridBagAdd(namePanel, new JLabel("Name:"), gBC2, GridBagConstraints.REMAINDER);
UIUtil.jGridBagAdd(namePanel, fontName = new JTextField(10), gBC2, GridBagConstraints.REMAINDER);
fontName.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
fontName.selectAll();
}
public void focusLost(FocusEvent e) {
}
});
gBC2.weighty = 1.0;
UIUtil.jGridBagAdd(namePanel, new JScrollPane(fontNameList), gBC2, GridBagConstraints.REMAINDER);
// Create the preview label
preview = new JLabel("Some sample text") {
public Dimension getMinimumSize() {
return new Dimension(super.getMinimumSize().width, 64);
}
public Dimension getPreferredSize() {
return new Dimension(320, 64);
}
};
preview.setBackground(Color.white);
preview.setForeground(Color.black);
preview.setOpaque(true);
preview.setHorizontalAlignment(SwingConstants.CENTER);
preview.setBorder(BorderFactory.createLineBorder(Color.black));
// Create the preview panel
JPanel previewPanel = new JPanel(new BorderLayout());
previewPanel.setBorder(BorderFactory.createTitledBorder("Preview"));
previewPanel.add(preview, BorderLayout.CENTER);
// Create the right panel
JPanel rightPanel = new JPanel(new BorderLayout());
if (stylePanel != null) {
rightPanel.add(stylePanel, BorderLayout.NORTH);
}
if (sizePanel != null) {
rightPanel.add(sizePanel, BorderLayout.CENTER);
}
// Listen for changes in the font name and select the closest font in
// the list
fontName.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
if (!adjusting) {