List of usage examples for javax.swing SwingConstants RIGHT
int RIGHT
To view the source code for javax.swing SwingConstants RIGHT.
Click Source Link
From source file:com.mgmtp.perfload.loadprofiles.ui.component.DoubleCellEditor.java
public DoubleCellEditor() { super(new JTextField()); final JTextField textField = (JTextField) getComponent(); textField.setHorizontalAlignment(SwingConstants.RIGHT); delegate = new EditorDelegate() { @Override//from w w w . j a v a2 s . c om public void setValue(final Object value) { textField.setText(value != null ? FORMAT.format(value) : null); } @Override public Object getCellEditorValue() { return textField.getText(); } }; textField.addActionListener(delegate); }
From source file:Main.java
public Main() { formTextFieldFormat = NumberFormat.getNumberInstance(); formTextFieldFormat.setMinimumFractionDigits(2); formTextFieldFormat.setMaximumFractionDigits(2); formTextFieldFormat.setRoundingMode(RoundingMode.HALF_UP); focusLabel.setPreferredSize(new Dimension(120, 27)); formTextField = new JFormattedTextField(formTextFieldFormat); formTextField.setValue(amount);//from w w w . ja va2 s .co m formTextField.setPreferredSize(new Dimension(120, 27)); formTextField.setHorizontalAlignment(SwingConstants.RIGHT); formTextField.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { formTextField.requestFocus(); formTextField.setText(formTextField.getText()); formTextField.selectAll(); } @Override public void focusLost(FocusEvent e) { double t1a1 = (((Number) formTextField.getValue()).doubleValue()); if (t1a1 < 1000) { formTextField.setValue(amount); } } }); docLabel.setPreferredSize(new Dimension(120, 27)); formTextField1 = new JFormattedTextField(formTextFieldFormat); formTextField1.setValue(amount); formTextField1.setHorizontalAlignment(SwingConstants.RIGHT); formTextField1.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { formTextField1.requestFocus(); formTextField1.setText(formTextField1.getText()); formTextField1.selectAll(); } @Override public void focusLost(FocusEvent e) { } }); formTextField1.getDocument().addDocumentListener(docListener); pnl = new JPanel(); pnl.setBorder(new EmptyBorder(2, 2, 2, 2)); pnl.setLayout(new GridLayout(2, 2)); pnl.add(focusLabel); pnl.add(formTextField); pnl.add(docLabel); pnl.add(formTextField1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(pnl, BorderLayout.CENTER); frame.setLocation(200, 200); frame.pack(); frame.setVisible(true); formTextFieldFocus1(); }
From source file:Main.java
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { JTextField editor = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); if (value != null) editor.setText(value.toString()); if (column == 0) { editor.setHorizontalAlignment(SwingConstants.CENTER); editor.setFont(new Font("Serif", Font.BOLD, 14)); } else {//from ww w. j av a 2 s .c o m editor.setHorizontalAlignment(SwingConstants.RIGHT); editor.setFont(new Font("Serif", Font.ITALIC, 12)); } return editor; }
From source file:FieldValidator.java
private static JComponent createContent() { Dimension labelSize = new Dimension(80, 20); Box box = Box.createVerticalBox(); // A single LayerUI for all the fields. LayerUI<JFormattedTextField> layerUI = new ValidationLayerUI(); // Number field. JLabel numberLabel = new JLabel("Number:"); numberLabel.setHorizontalAlignment(SwingConstants.RIGHT); numberLabel.setPreferredSize(labelSize); NumberFormat numberFormat = NumberFormat.getInstance(); JFormattedTextField numberField = new JFormattedTextField(numberFormat); numberField.setColumns(16);//from w w w.j a v a 2s . c o m numberField.setFocusLostBehavior(JFormattedTextField.PERSIST); numberField.setValue(42); JPanel numberPanel = new JPanel(); numberPanel.add(numberLabel); numberPanel.add(new JLayer<JFormattedTextField>(numberField, layerUI)); // Date field. JLabel dateLabel = new JLabel("Date:"); dateLabel.setHorizontalAlignment(SwingConstants.RIGHT); dateLabel.setPreferredSize(labelSize); DateFormat dateFormat = DateFormat.getDateInstance(); JFormattedTextField dateField = new JFormattedTextField(dateFormat); dateField.setColumns(16); dateField.setFocusLostBehavior(JFormattedTextField.PERSIST); dateField.setValue(new java.util.Date()); JPanel datePanel = new JPanel(); datePanel.add(dateLabel); datePanel.add(new JLayer<JFormattedTextField>(dateField, layerUI)); // Time field. JLabel timeLabel = new JLabel("Time:"); timeLabel.setHorizontalAlignment(SwingConstants.RIGHT); timeLabel.setPreferredSize(labelSize); DateFormat timeFormat = DateFormat.getTimeInstance(); JFormattedTextField timeField = new JFormattedTextField(timeFormat); timeField.setColumns(16); timeField.setFocusLostBehavior(JFormattedTextField.PERSIST); timeField.setValue(new java.util.Date()); JPanel timePanel = new JPanel(); timePanel.add(timeLabel); timePanel.add(new JLayer<JFormattedTextField>(timeField, layerUI)); // Put them all in the box. box.add(Box.createGlue()); box.add(numberPanel); box.add(Box.createGlue()); box.add(datePanel); box.add(Box.createGlue()); box.add(timePanel); return box; }
From source file:components.CustomIconDemo.java
public CustomIconDemo() { Icon leftButtonIcon = new ArrowIcon(SwingConstants.RIGHT); Icon middleButtonIcon = createImageIcon("images/middle.gif", "the middle button"); Icon rightButtonIcon = new ArrowIcon(SwingConstants.LEFT); b1 = new JButton("Disable middle button", leftButtonIcon); b1.setVerticalTextPosition(AbstractButton.CENTER); b1.setHorizontalTextPosition(AbstractButton.LEADING); b1.setMnemonic(KeyEvent.VK_D); b1.setActionCommand("disable"); b2 = new JButton("Middle button", middleButtonIcon); b2.setVerticalTextPosition(AbstractButton.BOTTOM); b2.setHorizontalTextPosition(AbstractButton.CENTER); b2.setMnemonic(KeyEvent.VK_M); b3 = new JButton("Enable middle button", rightButtonIcon); //Use the default text position of CENTER, TRAILING (RIGHT). b3.setMnemonic(KeyEvent.VK_E); b3.setActionCommand("enable"); b3.setEnabled(false);//from www . j a va2 s. c om //Listen for actions on buttons 1 and 3. b1.addActionListener(this); b3.addActionListener(this); b1.setToolTipText("Click this button to disable the middle button."); b2.setToolTipText("This middle button does nothing when you click it."); b3.setToolTipText("Click this button to enable the middle button."); //Add Components to this container, using the default FlowLayout. add(b1); add(b2); add(b3); }
From source file:TextComponentTest.java
public TextComponentFrame() { setTitle("TextComponentTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); final JTextField textField = new JTextField(); final JPasswordField passwordField = new JPasswordField(); JPanel northPanel = new JPanel(); northPanel.setLayout(new GridLayout(2, 2)); northPanel.add(new JLabel("User name: ", SwingConstants.RIGHT)); northPanel.add(textField);/*from ww w. j a va 2 s . c om*/ northPanel.add(new JLabel("Password: ", SwingConstants.RIGHT)); northPanel.add(passwordField); add(northPanel, BorderLayout.NORTH); final JTextArea textArea = new JTextArea(8, 40); JScrollPane scrollPane = new JScrollPane(textArea); add(scrollPane, BorderLayout.CENTER); // add button to append text into the text area JPanel southPanel = new JPanel(); JButton insertButton = new JButton("Insert"); southPanel.add(insertButton); insertButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { textArea.append("User name: " + textField.getText() + " Password: " + new String(passwordField.getPassword()) + "\n"); } }); add(southPanel, BorderLayout.SOUTH); // add a text area with scroll bars }
From source file:com.aw.core.format.FillerFormat.java
/** * Add null or empty string support/*w w w .jav a2s.co m*/ */ public Object parseObject(String source) { return fillFormat(source, fillerCharacter, lenght, SwingConstants.RIGHT, fillInclusiveEmptyString); }
From source file:LDAPTest.java
public LDAPFrame() { setTitle("LDAPTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel northPanel = new JPanel(); northPanel.setLayout(new java.awt.GridLayout(1, 2, 3, 1)); northPanel.add(new JLabel("uid", SwingConstants.RIGHT)); uidField = new JTextField(); northPanel.add(uidField);// www .ja v a 2 s.c o m add(northPanel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(); add(buttonPanel, BorderLayout.SOUTH); findButton = new JButton("Find"); findButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { findEntry(); } }); buttonPanel.add(findButton); saveButton = new JButton("Save"); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { saveEntry(); } }); buttonPanel.add(saveButton); deleteButton = new JButton("Delete"); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { deleteEntry(); } }); buttonPanel.add(deleteButton); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { try { if (context != null) context.close(); } catch (NamingException e) { e.printStackTrace(); } } }); }
From source file:CustomIconDemo.java
public CustomIconDemo() { Icon leftButtonIcon = new ArrowIcon(SwingConstants.RIGHT); Icon middleButtonIcon = createImageIcon("images/middle.gif", "the middle button"); Icon rightButtonIcon = new ArrowIcon(SwingConstants.LEFT); b1 = new JButton("Disable middle button", leftButtonIcon); b1.setVerticalTextPosition(AbstractButton.CENTER); b1.setHorizontalTextPosition(AbstractButton.LEADING); b1.setMnemonic(KeyEvent.VK_D); b1.setActionCommand("disable"); b2 = new JButton("Middle button", middleButtonIcon); b2.setVerticalTextPosition(AbstractButton.BOTTOM); b2.setHorizontalTextPosition(AbstractButton.CENTER); b2.setMnemonic(KeyEvent.VK_M); b3 = new JButton("Enable middle button", rightButtonIcon); // Use the default text position of CENTER, TRAILING (RIGHT). b3.setMnemonic(KeyEvent.VK_E); b3.setActionCommand("enable"); b3.setEnabled(false);/*from w w w . ja va 2 s .c o m*/ // Listen for actions on buttons 1 and 3. b1.addActionListener(this); b3.addActionListener(this); b1.setToolTipText("Click this button to disable the middle button."); b2.setToolTipText("This middle button does nothing when you click it."); b3.setToolTipText("Click this button to enable the middle button."); // Add Components to this container, using the default FlowLayout. add(b1); add(b2); add(b3); }
From source file:de.codesourcery.eve.skills.ui.utils.PersistentDialog.java
public PersistentDialog(String id, Icon icon, String title, String label, PersistenceType type, Kind kind) { super(null, title, ModalityType.APPLICATION_MODAL); if (kind == null) { throw new IllegalArgumentException("kind cannot be NULL"); }//from w w w .j a v a 2 s. c om if (StringUtils.isBlank(id)) { throw new IllegalArgumentException("id cannot be blank."); } if (type == null) { throw new IllegalArgumentException("type cannot be NULL"); } if (StringUtils.isBlank(label)) { throw new IllegalArgumentException("label cannot be blank."); } this.id = id; this.type = type; // configure checkbox isDialogEnabled = new JCheckBox("Always show this dialog ?", true); isDialogEnabled.setHorizontalTextPosition(SwingConstants.RIGHT); // add panel final JPanel content = new JPanel(); content.setLayout(new GridBagLayout()); content.add(new JLabel(icon), new ConstraintsBuilder().x(0).y(0).anchorWest().noResizing().useRelativeWidth().end()); content.add(new JLabel(label), new ConstraintsBuilder().x(1).y(0).anchorWest().resizeBoth().useRemainingWidth().end()); content.add(isDialogEnabled, new ConstraintsBuilder().x(0).y(1).width(2).anchorWest().noResizing().end()); final JPanel buttonPanel = new JPanel(); buttonPanel.add(okButton); final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == cancelButton) { wasCancelled = true; } dispose(); } }; okButton.addActionListener(listener); if (kind == Kind.CANCEL) { buttonPanel.add(cancelButton); cancelButton.addActionListener(listener); } content.add(buttonPanel, new ConstraintsBuilder().x(0).y(2).useRemainingSpace().end()); getContentPane().add(content); pack(); setLocationRelativeTo(null); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { wasCancelled = true; dispose(); } }); }