Example usage for javax.swing JTextField setHorizontalAlignment

List of usage examples for javax.swing JTextField setHorizontalAlignment

Introduction

In this page you can find the example usage for javax.swing JTextField setHorizontalAlignment.

Prototype

@BeanProperty(preferred = true, enumerationValues = { "JTextField.LEFT", "JTextField.CENTER",
        "JTextField.RIGHT", "JTextField.LEADING",
        "JTextField.TRAILING" }, description = "Set the field alignment to LEFT, CENTER, RIGHT, LEADING (the default) or TRAILING")
public void setHorizontalAlignment(int alignment) 

Source Link

Document

Sets the horizontal alignment of the text.

Usage

From source file:org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent.java

private void reconfigure(JTextField field) {
    field.setEnabled(false);/* w w w  . j  a v  a 2s  .  c  om*/
    field.setHorizontalAlignment(JTextField.RIGHT);
    field.setDisabledTextColor(Color.BLACK);
    field.setBorder(null);
}

From source file:org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent.java

private JPanel getBottomPanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new DefaultGridBagConstraints();

    // Colonne 1 : Infos
    c.gridx = 0;/*from   w w w  . ja va2 s . c  o m*/
    c.weightx = 1;
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.HORIZONTAL;

    panel.add(new TitledSeparator(getLabelFor("INFOS")), c);

    c.gridy++;
    c.weighty = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.BOTH;
    final JScrollPane scrollPane = new JScrollPane(this.infos);
    scrollPane.setBorder(null);
    panel.add(scrollPane, c);

    // Colonne 2 : Poids & autres
    DefaultProps props = DefaultNXProps.getInstance();
    Boolean b = props.getBooleanValue("ArticleShowPoids");
    final JTextField textPoidsTotal = new JTextField(8);
    JTextField poids = new JTextField();
    if (b) {
        final JPanel panelPoids = new JPanel();

        panelPoids.add(new JLabel(getLabelFor("T_POIDS")), c);

        textPoidsTotal.setEnabled(false);
        textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT);
        textPoidsTotal.setDisabledTextColor(Color.BLACK);

        panelPoids.add(textPoidsTotal, c);

        c.gridx++;
        c.gridy = 0;
        c.weightx = 0;
        c.weighty = 0;
        c.gridwidth = 1;
        c.gridheight = 2;
        c.fill = GridBagConstraints.NONE;
        c.anchor = GridBagConstraints.NORTHEAST;
        panel.add(panelPoids, c);
        DefaultGridBagConstraints.lockMinimumSize(panelPoids);
        addSQLObject(textPoidsTotal, "T_POIDS");
    } else {
        addSQLObject(poids, "T_POIDS");
    }

    DeviseField textPortHT = new DeviseField();
    ElementComboBox comboTaxePort = new ElementComboBox();

    if (getTable().contains("PORT_HT")) {
        addRequiredSQLObject(textPortHT, "PORT_HT");
        final JPanel panelPoids = new JPanel(new GridBagLayout());
        GridBagConstraints cPort = new DefaultGridBagConstraints();
        cPort.gridx = 0;
        cPort.weightx = 0;
        panelPoids.add(new JLabel(getLabelFor("PORT_HT")), cPort);
        textPortHT.setHorizontalAlignment(JTextField.RIGHT);
        cPort.gridx++;
        cPort.weightx = 1;
        panelPoids.add(textPortHT, cPort);

        cPort.gridy++;
        cPort.gridx = 0;
        cPort.weightx = 0;
        addRequiredSQLObject(comboTaxePort, "ID_TAXE_PORT");
        panelPoids.add(new JLabel(getLabelFor("ID_TAXE_PORT")), cPort);
        cPort.gridx++;
        cPort.weightx = 0;
        panelPoids.add(comboTaxePort, cPort);

        c.gridx++;
        c.gridy = 0;
        c.weightx = 0;
        c.weighty = 0;
        c.gridwidth = 1;
        c.gridheight = 2;
        c.fill = GridBagConstraints.NONE;
        c.anchor = GridBagConstraints.NORTHEAST;
        panel.add(panelPoids, c);
        DefaultGridBagConstraints.lockMinimumSize(panelPoids);
    }
    // Total

    DeviseField textRemiseHT = new DeviseField();
    DeviseField fieldHT = new DeviseField();
    DeviseField fieldTVA = new DeviseField();
    DeviseField fieldTTC = new DeviseField();
    DeviseField fieldDevise = new DeviseField();
    DeviseField fieldService = new DeviseField();
    fieldHT.setOpaque(false);
    fieldTVA.setOpaque(false);
    fieldTTC.setOpaque(false);
    fieldService.setOpaque(false);
    addRequiredSQLObject(fieldDevise, "T_DEVISE");
    addRequiredSQLObject(fieldHT, "T_HT");
    addRequiredSQLObject(fieldTVA, "T_TVA");

    addRequiredSQLObject(fieldTTC, "T_TTC");
    addRequiredSQLObject(fieldService, "T_SERVICE");
    final TotalPanel totalTTC = new TotalPanel(this.table, fieldHT, fieldTVA, fieldTTC, textPortHT,
            textRemiseHT, fieldService, null, fieldDevise, null, null,
            (getTable().contains("ID_TAXE_PORT") ? comboTaxePort : null));

    c.gridx++;
    c.gridy--;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 2;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.fill = GridBagConstraints.BOTH;
    c.weighty = 0;
    DefaultGridBagConstraints.lockMinimumSize(totalTTC);

    panel.add(totalTTC, c);

    c.gridy += 3;
    c.gridheight = 2;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    panel.add(getModuleTotalPanel(), c);

    table.getModel().addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            textPoidsTotal.setText(String.valueOf(table.getPoidsTotal()));
        }
    });

    textPortHT.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            totalTTC.updateTotal();
        }

        public void removeUpdate(DocumentEvent e) {
            totalTTC.updateTotal();
        }

        public void insertUpdate(DocumentEvent e) {
            totalTTC.updateTotal();
        }
    });

    comboTaxePort.addValueListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            // TODO Raccord de mthode auto-gnr
            totalTTC.updateTotal();
        }
    });

    textRemiseHT.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            totalTTC.updateTotal();
        }

        public void removeUpdate(DocumentEvent e) {
            totalTTC.updateTotal();
        }

        public void insertUpdate(DocumentEvent e) {
            totalTTC.updateTotal();
        }
    });
    return panel;
}

From source file:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java

@Override
public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException {

    double[] selectedValues;
    if (encoding == null) {
        selectedValues = null;/* w  w w .j  a  va  2s . com*/
    } else {
        selectedValues = NumericConditionEncoder.unencodeConditions(encoding);
    }

    final double[] extremeValues = generator.getExtremeNumericValues();
    this.removeAll();

    if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(Box.createHorizontalGlue());
        p.add(new JLabel("<html>All values are blank for this condition.</html>"));
        p.add(Box.createHorizontalGlue());
        this.add(p);
        return;
    }

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel p = ViewUtil.getClearPanel();
    ViewUtil.applyVerticalBoxLayout(p);

    JPanel labelPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(labelPanel);
    labelPanel.add(Box.createHorizontalGlue());
    labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": "));
    labelPanel.add(Box.createHorizontalGlue());
    ButtonGroup group = new ButtonGroup();
    //JRadioButton isButton = new JRadioButton("is within the following range:");
    //JRadioButton nullButton = new JRadioButton("is missing");
    //group.add(isButton);
    //group.add(nullButton);

    final JCheckBox nullButton = new JCheckBox("include missing values");

    JPanel bp = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(bp);
    p.add(labelPanel);
    p.add(bp);
    add(p);
    final DecimalRangeSlider slider = new DecimalRangeSlider();

    slider.setMajorTickSpacing(5);
    slider.setMinorTickSpacing(1);

    final JTextField fromBox = new JTextField();
    final JTextField toBox = new JTextField();

    nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding));

    nullButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                    ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                    extremeValues[1], nullButton.isSelected());
        }
    });

    fromBox.setMaximumSize(new Dimension(10000, 24));
    toBox.setMaximumSize(new Dimension(10000, 24));
    fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setHorizontalAlignment(JTextField.RIGHT);
    toBox.setHorizontalAlignment(JTextField.RIGHT);

    final JLabel fromLabel = new JLabel();
    final JLabel toLabel = new JLabel();

    ViewUtil.makeMini(fromLabel);
    ViewUtil.makeMini(toLabel);

    JPanel fromToContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(fromToContainer);
    fromToContainer.add(Box.createHorizontalGlue());
    fromToContainer.add(fromBox);
    fromToContainer.add(new JLabel(" - "));
    fromToContainer.add(toBox);
    fromToContainer.add(Box.createHorizontalGlue());

    JPanel minMaxContainer = ViewUtil.getClearPanel();
    minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS));

    JPanel sliderContainer = ViewUtil.getClearPanel();
    sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS));
    sliderContainer.add(slider);

    JPanel nullValueContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(nullValueContainer);
    nullValueContainer.add(Box.createHorizontalGlue());
    nullValueContainer.add(nullButton);
    nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue.
    nullValueContainer.add(Box.createHorizontalGlue());

    JPanel labelContainer = ViewUtil.getClearPanel();
    labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS));
    labelContainer.add(fromLabel);
    labelContainer.add(Box.createHorizontalGlue());
    labelContainer.add(toLabel);
    sliderContainer.add(labelContainer);
    minMaxContainer.add(Box.createHorizontalGlue());
    minMaxContainer.add(sliderContainer);
    minMaxContainer.add(Box.createHorizontalGlue());

    add(fromToContainer);
    add(minMaxContainer);
    add(nullValueContainer);
    add(Box.createVerticalBox());

    slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (slider.isEnabled()) {
                fromBox.setText(ViewUtil.numToString(slider.getLow()));
                toBox.setText(ViewUtil.numToString(slider.getHigh()));
                encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                        ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                        extremeValues[1], nullButton.isSelected());
            }
        }
    });

    final KeyListener keyListener = new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText()));
                setSelectedValues(slider, fromBox, toBox, selectedRage);
            }
        }

        private double getNumber(String s) {
            try {
                return Double.parseDouble(s.replaceAll(",", ""));
            } catch (NumberFormatException ignored) {
                return 0;
            }
        }
    };

    CaretListener caretListener = new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent ce) {
            if (!isAdjustingSlider) {
                try {
                    encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                            ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                            extremeValues[1], nullButton.isSelected());
                } catch (Exception e) {
                }
            }
        }
    };

    fromBox.addKeyListener(keyListener);

    toBox.addKeyListener(keyListener);

    fromBox.addCaretListener(caretListener);

    toBox.addCaretListener(caretListener);

    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            isAdjustingSlider = true;
            fromBox.setText(ViewUtil.numToString(slider.getLow()));
            toBox.setText(ViewUtil.numToString(slider.getHigh()));
            isAdjustingSlider = false;
        }
    });

    JPanel bottomContainer = new JPanel();

    bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS));

    bottomContainer.add(Box.createHorizontalGlue());

    add(bottomContainer);

    setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0,
            new Range(extremeValues[0], extremeValues[1]));

    if (encoding != null) {
        double[] d = NumericConditionEncoder.unencodeConditions(encoding);
        setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1]));
    }
}