En las conexiones con estos dos post @iMohammad, Increasing/Decreasing Font Size inside textArea using JButton y Changing Font Style when Clicking on a JButton Java ..., estoy frente a la cuestión muy divertido que venía de JComboBox
pasando setPrototypeDisplayValue
como un argumento para JComboBox's size
en la pantallaJComboBox PrototypeDisplayValue
complacer cómo puedo cambiar el tamaño me JComboBox
depende dinámicamente de Font
, misma que funciona correctamente por otros JComponents que he intentado en mi sscce
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ComboBoxFontChange extends JFrame {
private static final long serialVersionUID = 1L;
private JComboBox cbox = new JComboBox();
private JTextField tfield = new JTextField("Change");
private JLabel label = new JLabel("Cash");
private JButton button = new JButton("++ Font");
private JTextField text;
private JPanel panel = new JPanel();
public ComboBoxFontChange() {
super("Combo Box Font change");
text = (JTextField) cbox.getEditor().getEditorComponent();
cbox.addItem("Change");
cbox.addItem("Cash");
cbox.addItem("Font");
tfield.setColumns(5);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Font font = cbox.getFont();
font = font.deriveFont((float) (font.getSize2D() * 1.10));
cbox.setFont(font);
// EDIT
cbox.setPrototypeDisplayValue(cbox.getSelectedItem().toString());
tfield.setFont(font);
button.setFont(font);
label.setFont(font);
//panel.revalidate();
//panel.repaint();
pack();
}
});
//panel.setLayout(new GridLayout(2, 2, 10, 10));
panel.add(cbox);
panel.add(label);
panel.add(tfield);
panel.add(button);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(panel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ComboBoxFontChange frame = new ComboBoxFontChange();
frame.pack();
frame.setVisible(true);
}
});
}
}
por error He editado líneas de código incorrectas, manos rápidas, ahora es correcto como un ejemplo – mKorbel
Explique qué debe hacer el programa y qué hace en su lugar. Todo parece funcionar como se esperaba (JDK 1.7.0_02-ea). –
:-) el resto de nosotros todavía está en Java6, JComboBox todavía tiene el mismo tamaño en la pantalla – mKorbel