List of usage examples for javax.swing JTextField setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:Main.java
public static boolean verifyIntegerTextField(JTextField field) { try {/*from w w w . j a v a 2 s.com*/ Integer.valueOf(field.getText()); field.setBackground(Color.WHITE); } catch (NumberFormatException e) { field.setBackground(Color.LIGHT_GRAY); return false; } return true; }
From source file:com.sciaps.utils.Util.java
public static int validateZeroOrGreater(JTextField txtField) { Pattern pattern = Pattern.compile(POSITIVE_INT); if (pattern.matcher(txtField.getText()).matches()) { txtField.setBackground(Color.white); return getStringToInt(txtField.getText()); }/*from w ww .j a va 2 s .c om*/ txtField.setBackground(Color.red); return -1; }
From source file:com.sciaps.utils.Util.java
public static int validateOneOrGreater(JTextField txtField) { Pattern pattern = Pattern.compile(POSITIVE_INT); if (pattern.matcher(txtField.getText()).matches()) { int val = getStringToInt(txtField.getText()); if (val > 0) { txtField.setBackground(Color.white); return val; }/*from w w w .j a v a2s. c o m*/ } txtField.setBackground(Color.red); return -1; }
From source file:EvenOddRowCellRenderer.java
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JTextField editor = new JTextField(); if (value != null) editor.setText(value.toString()); editor.setBackground((row % 2 == 0) ? Color.white : Color.cyan); return editor; }
From source file:Main.java
public Main() { someComboBox.setFont(new Font("Serif", Font.BOLD, 16)); someComboBox.setEditable(true);// ww w . java 2s . c o m someComboBox.getEditor().getEditorComponent().setBackground(Color.YELLOW); ((JTextField) someComboBox.getEditor().getEditorComponent()).setBackground(Color.YELLOW); JTextField text = ((JTextField) editableComboBox.getEditor().getEditorComponent()); text.setBackground(Color.YELLOW); JComboBox coloredArrowsCombo = editableComboBox; Component[] comp = coloredArrowsCombo.getComponents(); for (int i = 0; i < comp.length; i++) { if (comp[i] instanceof MetalComboBoxButton) { MetalComboBoxButton coloredArrowsButton = (MetalComboBoxButton) comp[i]; coloredArrowsButton.setBackground(null); break; } } non_EditableComboBox.setFont(new Font("Serif", Font.BOLD, 16)); frame = new JFrame(); frame.setLayout(new GridLayout(0, 1, 10, 10)); frame.add(someComboBox); frame.add(editableComboBox); frame.add(non_EditableComboBox); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(100, 100); frame.pack(); frame.setVisible(true); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.SGRResultsForForm.java
public void refresh() { if (currentIndex < 0) return;/*ww w .j av a 2s. c o m*/ removeAll(); repaint(); if (!sgrPlugin.isReady()) { showMessage("SGR_NO_MATCHER"); return; } setCursor(new Cursor(Cursor.WAIT_CURSOR)); new SwingWorker<MatchResults, Void>() { private int index = currentIndex; @Override protected MatchResults doInBackground() throws Exception { int modelIndex = workbenchPaneSS.getSpreadSheet().convertRowIndexToModel(index); WorkbenchRow row = workbench.getRow(modelIndex); return isEmpty(row) ? null : sgrPlugin.doQuery(row); } @Override protected void done() { // if we changed indexes in the meantime, don't show this result. if (index != currentIndex) return; //removeAll(); try { results = get(); } catch (CancellationException e) { return; } catch (InterruptedException e) { return; } catch (ExecutionException e) { sgrFailed(e); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); return; } setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (results == null || results.matches.size() < 1) { showMessage("SGR_NO_RESULTS"); return; } float maxScore = sgrPlugin.getColorizer().getMaxScore(); if (maxScore == 0.0f) maxScore = 22.0f; StringBuilder columns = new StringBuilder("right:max(50dlu;p)"); for (Match result : results) { columns.append(", 4dlu, 150dlu:grow"); } String[] fields = columnOrdering.getFields(); StringBuilder rows = new StringBuilder(); for (int i = 0; i < fields.length - 1; i++) { rows.append("p, 4dlu,"); } rows.append("p"); FormLayout layout = new FormLayout(columns.toString(), rows.toString()); PanelBuilder builder = new PanelBuilder(layout, SGRResultsForForm.this); CellConstraints cc = new CellConstraints(); int y = 1; for (String heading : columnOrdering.getHeadings()) { builder.addLabel(heading + ":", cc.xy(1, y)); y += 2; } int x = 3; for (Match result : results) { y = 1; for (String field : fields) { String value; Color color; if (field.equals("id")) { value = result.match.id; color = SGRColors.colorForScore(result.score, maxScore); } else if (field.equals("score")) { value = String.format("%1$.2f", result.score); color = SGRColors.colorForScore(result.score, maxScore); } else { value = StringUtils.join(result.match.getFieldValues(field).toArray(), "; "); Float fieldContribution = result.fieldScoreContributions().get(field); color = SGRColors.colorForScore(result.score, maxScore, fieldContribution); } JTextField textField = new JTextField(value); textField.setBackground(color); textField.setEditable(false); textField.setCaretPosition(0); builder.add(textField, cc.xy(x, y)); y += 2; } x += 2; } getParent().validate(); } }.execute(); UsageTracker.incrUsageCount("SGR.MatchRow"); }
From source file:coreferenceresolver.gui.MarkupGUI.java
private JScrollPane newReviewPanel(Review review, int reviewId) throws BadLocationException { //Model/*ww w. j av a 2 s. com*/ ReviewElement reviewElement = new ReviewElement(); ScrollablePanel reviewPanel = new ScrollablePanel(); reviewPanel.setLayout(new BoxLayout(reviewPanel, BoxLayout.PAGE_AXIS)); JTextField title = new JTextField("NEW REVIEW " + reviewId); title.setBackground(Color.pink); reviewPanel.add(title); JTextArea reviewContentTxtArea = new JTextArea(); reviewContentTxtArea.setLineWrap(true); reviewContentTxtArea.setWrapStyleWord(true); reviewContentTxtArea.setEditable(false); reviewContentTxtArea.setText(review.getRawContent()); int chainId = 0; for (CorefChain cc : review.getCorefChains()) { for (int npId : cc.getChain()) { NounPhrase np = review.getNounPhrases().get(npId); Object highlighTag = reviewContentTxtArea.getHighlighter().addHighlight(np.getOffsetBegin(), np.getOffsetEnd() + 1, highlightPainters.get(chainId)); this.markupReviews.get(reviewId).getNounPhrases().get(npId).highlighterTag = highlighTag; } ++chainId; } reviewPanel.add(reviewContentTxtArea); ScrollablePanel markupsPanel = new ScrollablePanel(); markupsPanel.setLayout(new BoxLayout(markupsPanel, BoxLayout.PAGE_AXIS)); for (int i = 0; i < review.getNounPhrases().size(); ++i) { JScrollPane newMarkupPanel = newMarkupPanel(review.getNounPhrases().get(i), reviewElement); markupsPanel.add(newMarkupPanel); } JScrollPane scrollMarkupsPanel = new JScrollPane(markupsPanel); //Add Dimension for scrolling Dimension curScreenDimen = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); scrollMarkupsPanel.setPreferredSize(new Dimension((int) curScreenDimen.getWidth() - 50, 400)); reviewPanel.add(scrollMarkupsPanel); //MODEL reviewElement.reviewTextArea = reviewContentTxtArea; reviewElements.add(reviewElement); reviewPanel.add(new JSeparator(SwingConstants.HORIZONTAL)); reviewPanel.add(Box.createVerticalStrut(20)); JScrollPane scrollReviewPanel = new JScrollPane(reviewPanel); return scrollReviewPanel; }
From source file:edu.ku.brc.af.ui.forms.ViewFactory.java
/** * @param textField/*from w w w. j a v a 2 s . c om*/ * @param border * @param fgColor * @param bgColor * @param isOpaque */ public static void changeTextFieldUIForEdit(final JTextField textField, final Border border, final Color fgColor, final Color bgColor, final boolean isOpaque) { textField.setBorder(border); textField.setForeground(fgColor); textField.setEditable(true); textField.setFocusable(true); textField.setOpaque(isOpaque); textField.setBackground(bgColor); }
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 *//*from w w w. j a v a 2 s . 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:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJReferenceEditor.java
public void setEnabled(boolean value) { super.setEnabled(value); JTextField textField = getTextFieldQualifiedName(); if (textField != null) { textField.setEnabled(false);/* ww w. jav a 2 s . c o m*/ if (value) { textField.setBackground(Color.WHITE); } else { Container cont = getParent(); if (cont != null) { textField.setBackground(cont.getBackground()); } } textField.setForeground(Color.BLACK); textField.setDisabledTextColor(Color.BLACK); } JButton button = getButtonPickReference(); if (button != null) { button.setEnabled(value); } button = getButtonViewReference(); if (button != null) { button.setEnabled(true); } }