Example usage for javax.swing JComboBox setFont

List of usage examples for javax.swing JComboBox setFont

Introduction

In this page you can find the example usage for javax.swing JComboBox setFont.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The font for the component.")
public void setFont(Font font) 

Source Link

Document

Sets the font for this component.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame window = new JFrame("Example");

    JPanel contentPane = new JPanel();

    contentPane.setLayout(new GridBagLayout());

    JComboBox comboBoxfields = new JComboBox(COMBO_BOX_ELEMENTS);

    comboBoxfields.setFont(new Font("sansserif", Font.TRUETYPE_FONT | Font.PLAIN, 15));
    comboBoxfields.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));

    comboBoxfields.setMaximumRowCount(5);

    comboBoxfields.addActionListener(/*  www . j  a  va  2  s.  c  o  m*/
            e -> System.out.println("'" + comboBoxfields.getSelectedItem().toString() + "'" + " was selected"));

    contentPane.add(comboBoxfields);

    window.add(contentPane);
    window.setSize(500, 500);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
}

From source file:Main.java

public static void setComboLayout(JComboBox<?> combo, int w, int h, String name) {
    combo.setPreferredSize(getControlDimension(w, h));
    combo.setMinimumSize(getControlDimension(w, h));
    combo.setFont(getFont());
    combo.setName(name);//from   w  w w  .  ja va  2 s. co  m
}

From source file:org.jfree.chart.demo.RightPanel.java

public RightPanel(int x, int y, int width, int height, String baude[], String name[]) {

    setBackground(new Color(176, 199, 246));

    this.width = width;
    this.height = height;

    Data[0] = "8";
    Data[1] = "9";

    Name = name;/*from ww  w .  j  a  va 2  s  .c o m*/
    Baude = baude;

    setLayout(new GridLayout(8, 1, 0, 0));

    lblName = new JLabel("Name");
    lblName.setHorizontalAlignment(SwingConstants.CENTER);
    lblName.setFont(new Font("Arial", 15, 16));
    add(lblName);

    comboBox = new JComboBox(Name);
    comboBox.setFont(new Font("Arial", 15, 16));
    add(comboBox);

    JLabel lblBaude = new JLabel("Baude");
    lblBaude.setFont(new Font("Arial", 15, 16));
    lblBaude.setHorizontalAlignment(SwingConstants.CENTER);
    add(lblBaude);

    final JComboBox comboBox_1 = new JComboBox(Baude);
    comboBox_1.setFont(new Font("Arial", 15, 16));
    add(comboBox_1);

    JLabel lblDataSize = new JLabel("Data size");
    lblDataSize.setHorizontalAlignment(SwingConstants.CENTER);
    lblDataSize.setFont(new Font("Arial", 15, 16));
    add(lblDataSize);

    final JComboBox comboBox_2 = new JComboBox(Data);
    comboBox_2.setFont(new Font("Arial", 15, 16));
    add(comboBox_2);

    JSeparator separator = new JSeparator();
    add(separator);

    btnOpen = new JButton("Open");
    btnOpen.setFont(new Font("Arial", 15, 16));
    btnOpen.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (btnOpen.getText() == "Open") {
                btnOpen.setText("Close");
                open = true;
                int baude = 9600, data = 8;
                try {
                    baude = Integer.parseInt((String) comboBox_1.getSelectedItem());
                    data = Integer.parseInt((String) comboBox_2.getSelectedItem());
                } catch (Exception e) {
                    errors += "Enter correct Bauderate\n";
                    error_flag = true;

                }
                comport = new Comport((String) comboBox.getSelectedItem(), baude, data);
                comport.start();

            } else {
                comport.flag = false;
                btnOpen.setText("Open");
                open = false;

                comport.close();
                //   comport.stop();

                System.out.println("Comport = " + comport.isAlive());
                System.out.println("Comport life  = " + comport.get_life());

            }
        }
    });
    add(btnOpen);
    setBounds(x + 50, y, width - 40, height - 20);
    err.setBounds(x + 50, y, 50, 50);
    //add(err);

}

From source file:cs.gui.stats.PerformanceStats.java

public JPanel buildPlotDisplayManagementPanel(ValueAxis valueAxis, DateAxis dateAxis, JComboBox ddlScope) {
    JPanel panel = new JPanel(new FlowLayout());

    JLabel lblDisplayScope = new JLabel("Time Range:");

    ddlScope = fillScopeDDL(ddlScope);/*from www  . j av  a  2 s  .co  m*/
    lblDisplayScope.setFont(new Font("Italic", 1, 10));
    ddlScope.setFont(new Font("Italic", 1, 10));

    panel.add(lblDisplayScope);
    panel.add(ddlScope);

    ddlScope.addActionListener(new ComboBoxListener(valueAxis, dateAxis));

    return panel;
}

From source file:dk.dma.epd.common.prototype.gui.route.RoutePropertiesDialogCommon.java

/**
 * Initializes the user interface//from   w  ww. j  a  va2 s. c o m
 */
private void initGui() {
    Insets insets1 = new Insets(5, 5, 0, 5);
    Insets insets2 = new Insets(5, 25, 0, 5);
    Insets insets3 = new Insets(5, 5, 0, 0);
    Insets insets4 = new Insets(5, 0, 0, 5);
    Insets insets5 = new Insets(5, 5, 5, 5);
    Insets insets6 = new Insets(5, 25, 5, 5);
    Insets insets10 = new Insets(10, 10, 10, 10);

    JPanel content = new JPanel(new GridBagLayout());
    getContentPane().add(content);

    // ********************************
    // ** Route properties panel
    // ********************************

    JPanel routeProps = new JPanel(new GridBagLayout());
    routeProps.setBorder(new TitledBorder(new LineBorder(Color.black), "Route Properties"));
    content.add(routeProps, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, WEST, NONE, insets10, 0, 0));

    // Auto-completion
    List<String> strings = new ArrayList<>();
    strings.add("Copenhagen");
    strings.add("Oslo");
    AutoCompleteDecorator.decorate(originTxT, strings, false);
    AutoCompleteDecorator.decorate(destinationTxT, strings, false);

    // Column 1 widgets
    int gridY = 0;
    nameTxT.setEditable(!readOnlyRoute);
    nameTxT.getDocument().addDocumentListener(new TextFieldChangeListener(nameTxT));
    routeProps.add(new JLabel("Name:"),
            new GridBagConstraints(0, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets1, 0, 0));
    routeProps.add(fixSize(nameTxT, 120),
            new GridBagConstraints(1, gridY++, 1, 1, 0.0, 0.0, WEST, NONE, insets1, 0, 0));

    originTxT.setEditable(!readOnlyRoute);
    originTxT.getDocument().addDocumentListener(new TextFieldChangeListener(originTxT));
    routeProps.add(new JLabel("Origin:"),
            new GridBagConstraints(0, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets1, 0, 0));
    routeProps.add(fixSize(originTxT, 120),
            new GridBagConstraints(1, gridY++, 1, 1, 0.0, 0.0, WEST, NONE, insets1, 0, 0));

    destinationTxT.setEnabled(!readOnlyRoute);
    destinationTxT.getDocument().addDocumentListener(new TextFieldChangeListener(destinationTxT));
    routeProps.add(new JLabel("Destination:"),
            new GridBagConstraints(0, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets1, 0, 0));
    routeProps.add(fixSize(destinationTxT, 120),
            new GridBagConstraints(1, gridY++, 1, 1, 0.0, 0.0, WEST, NONE, insets1, 0, 0));

    distanceTxT.setEditable(false);
    routeProps.add(new JLabel("Total Distance:"),
            new GridBagConstraints(0, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));
    routeProps.add(fixSize(distanceTxT, 120),
            new GridBagConstraints(1, gridY++, 1, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));

    // Column 2 widgets
    gridY = 0;
    int h = (int) departurePicker.getPreferredSize().getHeight();
    initDatePicker(departurePicker, departureSpinner);
    routeProps.add(new JLabel("Estimated Time of Departure:"),
            new GridBagConstraints(2, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets2, 0, 0));
    routeProps.add(fixSize(departurePicker, 120),
            new GridBagConstraints(3, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets3, 0, 0));
    routeProps.add(fixSize(departureSpinner, 60, h),
            new GridBagConstraints(4, gridY++, 1, 1, 0.0, 0.0, WEST, NONE, insets4, 0, 0));

    initDatePicker(arrivalPicker, arrivalSpinner);
    routeProps.add(new JLabel("Estimated Time of Arrival:"),
            new GridBagConstraints(2, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets2, 0, 0));
    routeProps.add(fixSize(arrivalPicker, 120),
            new GridBagConstraints(3, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets3, 0, 0));
    routeProps.add(fixSize(arrivalSpinner, 60, h),
            new GridBagConstraints(4, gridY++, 1, 1, 0.0, 0.0, WEST, NONE, insets4, 0, 0));

    inrouteTxT.setEditable(false);
    routeProps.add(new JLabel("Estimated Time in-route:"),
            new GridBagConstraints(2, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets2, 0, 0));
    routeProps.add(fixSize(inrouteTxT, 180),
            new GridBagConstraints(3, gridY++, 2, 1, 0.0, 0.0, WEST, NONE, insets1, 0, 0));

    etaCalculationTime.setEnabled(!readOnlyRoute);
    etaCalculationTime.addActionListener(this);
    routeProps.add(new JLabel("Calculate TTG/ETA using:"),
            new GridBagConstraints(2, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets6, 0, 0));
    routeProps.add(fixSize(etaCalculationTime, 180),
            new GridBagConstraints(3, gridY++, 2, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));

    allSpeeds.setEnabled(!readOnlyRoute);
    allSpeedsBtn.setEnabled(!readOnlyRoute);
    routeProps.add(new JLabel("Speed all legs: "),
            new GridBagConstraints(2, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets2, 0, 0));
    routeProps.add(fixSize(allSpeeds, 60),
            new GridBagConstraints(3, gridY, 1, 1, 0.0, 0.0, WEST, NONE, insets3, 0, 0));
    routeProps.add(fixSize(allSpeedsBtn, 60, h),
            new GridBagConstraints(4, gridY++, 1, 1, 0.0, 0.0, WEST, NONE, insets4, 0, 0));

    routeProps.add(new JLabel(""),
            new GridBagConstraints(5, 0, 1, 1, 1.0, 0.0, WEST, HORIZONTAL, insets2, 0, 0));

    // ********************************
    // ** Route detail panel
    // ********************************

    routeTableModel = createRouteTableModel();
    routeDetailTable = new DeltaTable(routeTableModel, DELTA_START_COL_INDEX);
    routeDetailTable.setTableFont(routeDetailTable.getTableFont().deriveFont(10.0f));
    routeDetailTable.setNonEditableBgColor(UIManager.getColor("Table.background").darker().darker());
    routeDetailTable.addListSelectionListener(this);

    // Set the minimum column widths
    for (int x = 0; x < COL_MIN_WIDTHS.length; x++) {
        routeDetailTable.getColumn(x).setMinWidth(COL_MIN_WIDTHS[x]);
    }

    // Configure lock column
    routeDetailTable.fixColumnWidth(0, COL_MIN_WIDTHS[0]);
    routeDetailTable.getColumn(0).setCellRenderer(new LockTableCell.CustomBooleanCellRenderer());
    routeDetailTable.getColumn(0).setCellEditor(new LockTableCell.CustomBooleanCellEditor());

    // Configure ETA column
    routeDetailTable.getColumn(7).setCellEditor(new EtaEditor());

    // Configure heading column
    JComboBox<Heading> headingCombo = new JComboBox<>(Heading.values());
    headingCombo.setFont(headingCombo.getFont().deriveFont(10.0f));
    routeDetailTable.getColumn(10).setCellEditor(new DefaultCellEditor(headingCombo));

    JPanel routeTablePanel = new JPanel(new BorderLayout());
    routeTablePanel.add(routeDetailTable, BorderLayout.CENTER);
    routeTablePanel.setBorder(new TitledBorder(new LineBorder(Color.black), "Route Details"));
    content.add(routeTablePanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, NORTHWEST, BOTH, insets10, 0, 0));

    // ********************************
    // ** Button panel
    // ********************************

    JPanel btnPanel = new JPanel(new GridBagLayout());
    content.add(btnPanel, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, NORTHWEST, HORIZONTAL, insets10, 0, 0));

    btnZoomToRoute.addActionListener(this);
    btnZoomToWp.addActionListener(this);
    btnDelete.addActionListener(this);
    btnActivate.addActionListener(this);
    btnClose.addActionListener(this);
    cbVisible.addActionListener(this);
    allSpeedsBtn.addActionListener(this);
    getRootPane().setDefaultButton(btnClose);
    btnPanel.add(btnZoomToRoute, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));
    btnPanel.add(btnZoomToWp, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));
    btnPanel.add(btnDelete, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));
    btnPanel.add(btnActivate, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));
    btnPanel.add(cbVisible, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, WEST, NONE, insets5, 0, 0));
    btnPanel.add(btnClose, new GridBagConstraints(5, 0, 1, 1, 1.0, 0.0, EAST, NONE, insets5, 0, 0));
}

From source file:com.osparking.osparking.Settings_System.java

private void prepareComPortControls() {
    E_Board1_comLabel = new javax.swing.JLabel();
    E_Board2_comLabel = new javax.swing.JLabel();
    E_Board3_comLabel = new javax.swing.JLabel();
    E_Board4_comLabel = new javax.swing.JLabel();
    GateBar1_comLabel = new javax.swing.JLabel();
    GateBar2_comLabel = new javax.swing.JLabel();
    GateBar3_comLabel = new javax.swing.JLabel();
    GateBar4_comLabel = new javax.swing.JLabel();

    E_Board1_comLabel.setName("E_Board1_comLabel"); // E_Board1_comLabel
    E_Board2_comLabel.setName("E_Board2_comLabel");
    E_Board3_comLabel.setName("E_Board3_comLabel");
    E_Board4_comLabel.setName("E_Board4_comLabel");
    GateBar1_comLabel.setName("GateBar1_comLabel");
    GateBar2_comLabel.setName("GateBar2_comLabel");
    GateBar3_comLabel.setName("GateBar3_comLabel");
    GateBar4_comLabel.setName("GateBar4_comLabel");

    augmentComponentMap(E_Board1_comLabel, componentMap);
    augmentComponentMap(E_Board2_comLabel, componentMap);
    augmentComponentMap(E_Board3_comLabel, componentMap);
    augmentComponentMap(E_Board4_comLabel, componentMap);
    augmentComponentMap(GateBar1_comLabel, componentMap);
    augmentComponentMap(GateBar2_comLabel, componentMap);
    augmentComponentMap(GateBar3_comLabel, componentMap);
    augmentComponentMap(GateBar4_comLabel, componentMap);

    initComPortIDLabel(E_Board1_comLabel);
    initComPortIDLabel(E_Board2_comLabel);
    initComPortIDLabel(E_Board3_comLabel);
    initComPortIDLabel(E_Board4_comLabel);
    initComPortIDLabel(GateBar1_comLabel);
    initComPortIDLabel(GateBar2_comLabel);
    initComPortIDLabel(GateBar3_comLabel);
    initComPortIDLabel(GateBar4_comLabel);

    E_Board1_comID_CBox = new JComboBox();
    E_Board2_comID_CBox = new JComboBox();
    E_Board3_comID_CBox = new JComboBox();
    E_Board4_comID_CBox = new JComboBox();
    GateBar1_comID_CBox = new JComboBox();
    GateBar2_comID_CBox = new JComboBox();
    GateBar3_comID_CBox = new JComboBox();
    GateBar4_comID_CBox = new JComboBox();

    E_Board1_comID_CBox.setName("E_Board1_comID_CBox");
    E_Board2_comID_CBox.setName("E_Board2_comID_CBox");
    E_Board3_comID_CBox.setName("E_Board3_comID_CBox");
    E_Board4_comID_CBox.setName("E_Board4_comID_CBox");
    GateBar1_comID_CBox.setName("GateBar1_comID_CBox");
    GateBar2_comID_CBox.setName("GateBar2_comID_CBox");
    GateBar3_comID_CBox.setName("GateBar3_comID_CBox");
    GateBar4_comID_CBox.setName("GateBar4_comID_CBox");

    augmentComponentMap(E_Board1_comID_CBox, componentMap);
    augmentComponentMap(E_Board2_comID_CBox, componentMap);
    augmentComponentMap(E_Board3_comID_CBox, componentMap);
    augmentComponentMap(E_Board4_comID_CBox, componentMap);
    augmentComponentMap(GateBar1_comID_CBox, componentMap);
    augmentComponentMap(GateBar2_comID_CBox, componentMap);
    augmentComponentMap(GateBar3_comID_CBox, componentMap);
    augmentComponentMap(GateBar4_comID_CBox, componentMap);

    //<editor-fold desc="-- Initialize other properties of COM ID combobox">
    for (int gate = 1; gate <= gateCount; gate++) {
        for (final DeviceType devType : DeviceType.values()) {
            String name = devType.name() + gate + "_comID_CBox";
            final JComboBox comIDcBox = ((JComboBox) getComponentByName(name));

            if (comIDcBox != null) {
                comIDcBox.setFont(new java.awt.Font(font_Type, font_Style, font_Size));
                comIDcBox.setModel(new javax.swing.DefaultComboBoxModel(
                        new String[] { "1", "2", "3", "4", "5", "6", "7", "8" }));
                comIDcBox.setMinimumSize(new java.awt.Dimension(50, CBOX_HEIGHT));
                comIDcBox.setPreferredSize(new java.awt.Dimension(50, CBOX_HEIGHT));
                final int gateNo = gate;

                comIDcBox.addItemListener(new java.awt.event.ItemListener() {
                    public void itemStateChanged(java.awt.event.ItemEvent evt) {
                        if (evt.getStateChange() == ItemEvent.SELECTED) {
                            String COM_ID = (String) comIDcBox.getSelectedItem();
                            if (COM_ID.equals(deviceComID[devType.ordinal()][gateNo])) {
                                changedControls.remove(comIDcBox);
                            } else {
                                changedControls.add(comIDcBox);
                            }//from   w w w .  j  a  v a2s  .co  m
                        }
                    }
                });
            }
        }
    }
    //</editor-fold>
}

From source file:skoa.helpers.ConfiguracionGraficas.java

private void vistaIntermedia4() {
    vacia = true; //Una vez llegado aqu, ya se empieza a llenar la carpeta destino.
    for (int i = 0; i < datos.getComponentCount(); i++)
        datos.remove(i); //Borra 
    datos.removeAll();/*from  ww  w. ja  v  a2 s .  co  m*/
    JPanel p = new JPanel();
    p.setLayout(new GridLayout(3, 1));
    //JLabel l=new JLabel(" Grfica "+ng+":  "+"Direcciones: "+seleccionadas);
    //l.setFont(new Font("Tahoma",Font.BOLD,12));
    p2 = new JPanel();
    p2.setLayout(new GridLayout(1, 3));
    l = new JLabel(" Grfica " + ng + ":  " + "Direcciones: ");
    l.setFont(new Font("Tahoma", Font.BOLD, 12));
    p2.add(l);
    Vector<String> AuxSeleccionadas = new Vector<String>();
    AuxSeleccionadas.addAll(seleccionadas);
    JComboBox laux = new JComboBox(AuxSeleccionadas);
    laux.setEditable(false);
    laux.setSelectedIndex(0);
    laux.setFont(new Font("Tahoma", Font.ITALIC, 12));
    //p2.add(lo);
    p2.add(laux);//para que se mantengan las anteriores al aadir nuevas.
    p2.add(new JPanel());
    ng++;
    //p.add(l);
    p.add(p2);
    String l2 = "                  ";
    if (c == 1) {
        if (ejeDual.contentEquals("dual"))
            l2 = l2 + "Consulta: Evolucin temporal dual, ";
        else
            l2 = l2 + "Consulta: Evolucin temporal, ";
    } else if (c == 2) {
        if (ejeDual.contentEquals("dual"))
            l2 = l2 + "Consulta: Acumulacin por intervalos temporales dual, ";
        else
            l2 = l2 + "Consulta: Acumulacin por intervalos temporales, ";
    } else if (c == 3)
        l2 = l2 + "Consulta: Mx-Mn-Med por intervalos temporales, ";
    else if (c == 5)
        l2 = l2 + "Consulta: Evolucin de diferencias en %, ";
    else if (c == 6)
        l2 = l2 + "Consulta: Evolucin de diferencias, ";
    if (f == 1)
        l2 = l2 + "de un intervalo.";
    else if (f == 2)
        l2 = l2 + "completa.";
    l = new JLabel(l2);
    l.setFont(new Font("Tahoma", Font.PLAIN, 12));
    p.add(l);
    l2 = "                  ";
    if (f == 1) {
        l2 = l2 + "Desde " + fini + " hasta " + ffin;
        if (c == 2 || c == 3)
            l2 = l2 + " con rango de " + rango + " horas.";
        if (c > 4)
            l2 = l2 + " con rango de " + rango + " minutos.";
    }
    if (f == 2) {
        if (c == 2 || c == 3)
            l2 = l2 + "Con rango de " + rango + " horas.";
        if (c > 4)
            l2 = l2 + "Con rango de " + rango + " minutos.";
    }
    l = new JLabel(l2);
    l.setFont(new Font("Tahoma", Font.PLAIN, 12));
    p.add(l);
    mantenerVista(p);
    //EN ESTE PUNTO DEL CDIGO, ANTES DE RESTABLECERVALORES, INVOCAR A LAS CONSULTAS (al constructor)
    //PARA GENERAR LA CONSULTA CORRESPONDIENTE ANTES DE OBTENER LOS PARMETROS DE LA SIGUIENTE CONSULTA.
    //nh indica el hilo que se tiene que coger para la consulta actual.
    try {
        if (nh == 1) { //Los hilos en su constructor llaman start.
            h1 = new Consultas(H, c, f, fini, ffin, rango, direcciones, NombreCarpetaActual, dataSource);
            h1.start();
        } else if (nh == 2) {
            h2 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource);
            h2.start();
        } else if (nh == 3) {
            h3 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource);
            h3.start();
        } else if (nh == 4) {
            h4 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource);
            h4.start();
        }
        nh++;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    consultasDuales.add(ejeDual);
    JPanel gen = new JPanel();
    gen.setLayout(new GridLayout(2, 1));
    gen.add(new JPanel());
    gen.add(generar);
    obtenidos.add(gen);
    reestablecerPaneles();
    cargarVista();
}