List of usage examples for javax.swing JTextField getBorder
public Border getBorder()
null
if no border is currently set. From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel p = new JPanel(new BorderLayout()); JTextField tf = new JTextField(5); JLabel label = new JLabel(new ImageIcon("Test.gif")); label.setOpaque(true);// www .ja v a 2s . c o m label.setBackground(tf.getBackground()); label.setPreferredSize(new Dimension(label.getPreferredSize().width, tf.getPreferredSize().height)); p.setBorder(tf.getBorder()); tf.setBorder(null); p.add(label, BorderLayout.WEST); p.add(tf, BorderLayout.CENTER); JPanel p1 = new JPanel(); p1.add(p); getContentPane().add(p1); pack(); setLocationRelativeTo(null); }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextFieldSingle.java
public void setAutoNumberEnabled(boolean turnOn) { if (isAutoFmtOn != turnOn && formatter.isIncrementer()) { if (turnOn) { ViewFactory.changeTextFieldUIForDisplay(this, false); } else {// ww w .j a v a 2 s . c o m JTextField tf = new JTextField(); // Cheap and easy way to get original UI ViewFactory.changeTextFieldUIForEdit(this, tf.getBorder(), tf.getForeground(), tf.getBackground(), tf.isOpaque()); } } isAutoFmtOn = turnOn; }
From source file:edu.ku.brc.af.ui.forms.ViewFactory.java
/** * Makes adjusts to the border and the colors to make it "flat" for display mode. * @param textField the text field to be flattened * @param isTransparent make the background transparent instead of using the viewFieldColor */// w ww .jav a2s.co m public static void changeTextFieldUIForDisplay(final JTextField textField, final Color borderColor, final boolean isTransparent) { Insets insets = textField.getBorder().getBorderInsets(textField); if (borderColor != null) { textField.setBorder(BorderFactory.createMatteBorder(Math.min(insets.top, 3), Math.min(insets.left, 3), Math.min(insets.bottom, 3), Math.min(insets.right, 3), borderColor)); } else { textField.setBorder(BorderFactory.createEmptyBorder(Math.min(insets.top, 3), Math.min(insets.left, 3), Math.min(insets.bottom, 3), Math.min(insets.right, 3))); } textField.setForeground(Color.BLACK); textField.setEditable(false); //textField.setFocusable(false); // rods - commented out because it makes it so you can't select and copy textField.setOpaque(!isTransparent); if (isTransparent) { textField.setBackground(null); } else if (viewFieldColor != null) { textField.setBackground(viewFieldColor.getColor()); } }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextField.java
/** * Creates the various UI Components for the formatter. *///from w w w. j a v a 2 s . com protected void createUI() { CellConstraints cc = new CellConstraints(); if (isViewOnly || (formatter != null && !formatter.isUserInputNeeded() && fields != null && fields.size() == 1)) { viewtextField = new JTextField(); setControlSize(viewtextField); // Remove by rods 12/5/08 this messes thihngs up // values don't get inserted correctly, shouldn't be needed anyway //JFormattedDoc document = new JFormattedDoc(viewtextField, formatter, formatter.getFields().get(0)); //viewtextField.setDocument(document); //document.addDocumentListener(this); //documents.add(document); ViewFactory.changeTextFieldUIForDisplay(viewtextField, false); PanelBuilder builder = new PanelBuilder(new FormLayout("1px,f:p:g,1px", "1px,f:p:g,1px"), this); builder.add(viewtextField, cc.xy(2, 2)); bgColor = viewtextField.getBackground(); } else { JTextField txt = new JTextField(); Font txtFont = txt.getFont(); Font font = new Font("Courier", Font.PLAIN, txtFont.getSize()); BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setFont(font); FontMetrics fm = g.getFontMetrics(font); g.dispose(); Insets ins = txt.getBorder().getBorderInsets(txt); int baseWidth = ins.left + ins.right; bgColor = txt.getBackground(); StringBuilder sb = new StringBuilder("1px"); for (UIFieldFormatterField f : fields) { sb.append(","); if (f.getType() == FieldType.separator || f.getType() == FieldType.constant) { sb.append('p'); } else { sb.append(((fm.getMaxAdvance() * f.getSize()) + baseWidth) + "px"); } } sb.append(",1px"); PanelBuilder builder = new PanelBuilder(new FormLayout(sb.toString(), "1px,P:G,1px"), this); comps = new JComponent[fields.size()]; int inx = 0; for (UIFieldFormatterField f : fields) { JComponent comp = null; JComponent tfToAdd = null; if (f.getType() == FieldType.separator || f.getType() == FieldType.constant) { comp = createLabel(f.getValue()); if (f.getType() == FieldType.constant) { comp.setBackground(Color.WHITE); comp.setOpaque(true); } tfToAdd = comp; } else { JTextField tf = new BGTextField(f.getSize(), isViewOnly ? "" : f.getValue()); tfToAdd = tf; if (inx == 0) { tf.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { checkForPaste(e); } }); } JFormattedDoc document = new JFormattedDoc(tf, formatter, f); tf.setDocument(document); document.addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { isChanged = true; if (!shouldIgnoreNotifyDoc) { String fldStr = getText(); int len = StringUtils.isNotEmpty(fldStr) ? fldStr.length() : 0; if (formatter != null && len > 0 && formatter.isLengthOK(len)) { setState(formatter.isValid(fldStr) ? UIValidatable.ErrorType.Valid : UIValidatable.ErrorType.Error); repaint(); } //validateState(); if (changeListener != null) { changeListener.stateChanged(new ChangeEvent(this)); } if (documentListeners != null) { for (DocumentListener dl : documentListeners) { dl.changedUpdate(null); } } } currCachedValue = null; } }); documents.add(document); addFocusAdapter(tf); comp = tf; comp.setFont(font); if (f.isIncrementer()) { editTF = tf; cardLayout = new CardLayout(); cardPanel = new JPanel(cardLayout); cardPanel.add("edit", tf); viewTF = new BGTextField(f.getSize(), isViewOnly ? "" : f.getValue()); viewTF.setDocument(document); cardPanel.add("view", viewTF); cardLayout.show(cardPanel, "view"); comp = cardPanel; tfToAdd = cardPanel; } } setControlSize(tfToAdd); builder.add(comp, cc.xy(inx + 2, 2)); comps[inx] = tfToAdd; inx++; } } }
From source file:org.scify.talkandplay.gui.users.UserFormPanel.java
private void disableTextField(JTextField textField) { textField.setEnabled(false);// w w w .j ava 2s. co m textField.setForeground(Color.decode(UIConstants.disabledColor)); textField.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.decode(UIConstants.disabledColor))); textField.setBorder(BorderFactory.createCompoundBorder(textField.getBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5))); }
From source file:org.scify.talkandplay.gui.users.UserFormPanel.java
private void enableTextField(JTextField textField) { textField.setEnabled(true);//from w w w.j ava 2s. com textField.setForeground(Color.decode(UIConstants.green)); textField.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.decode(UIConstants.green))); textField.setBorder(BorderFactory.createCompoundBorder(textField.getBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5))); }