List of usage examples for javax.swing JComponent setFont
@BeanProperty(preferred = true, visualUpdate = true, description = "The font for the component.") public void setFont(Font font)
From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JTableInfoForCMFile.java
synchronized public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);//from www .j a v a 2 s.c o m if (value == null) { comp.setToolTipText(null); return comp; } comp.setToolTipText(String.valueOf(value)); if (row >= table.getRowCount()) { log.debug("row > table.getRowCount()"); return comp; } switch (column) { case TableModelForCMFile.COL_COMPONENT_NAME: case TableModelForCMFile.COL_LICENSE_NAME: setHorizontalAlignment(SwingConstants.LEFT); break; case TableModelForCMFile.COL_VERSION_NAME: case TableModelForCMFile.COL_USAGE: case TableModelForCMFile.COL_STATUS: case TableModelForCMFile.COL_PERCENTAGE: case TableModelForCMFile.COL_MATCHED_FILE: setHorizontalAlignment(SwingConstants.CENTER); break; } if (table.getValueAt(row, TableModelForCMFile.COL_STATUS) == null) return comp; String status = table.getValueAt(row, TableModelForCMFile.COL_STATUS).toString(); String licenseName = table.getValueAt(row, TableModelForCMFile.COL_LICENSE_NAME).toString(); if (status.equals(AbstractMatchInfo.IDENTIFIED)) { comp.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 12)); comp.setForeground(NORMAL_COLOR); } else if ((status.equals(AbstractMatchInfo.REJECTED)) || (status.equals(AbstractMatchInfo.DECLARED))) { comp.setForeground(new Color(150, 150, 150)); } else if (status.equals(AbstractMatchInfo.PENDING)) { if (identifiedStringSearchLicense != null && !identifiedStringSearchLicense.equals("")) { String currentRowLicense = "" + licenseName; if (identifiedStringSearchLicense.equals(currentRowLicense)) { comp.setForeground(NORMAL_COLOR); } else { comp.setForeground(GRAY_COLOR); } } else { comp.setForeground(NORMAL_COLOR); } } return comp; }
From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JTableInfoForCMFolder.java
synchronized public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);/*from w w w.ja va 2s . c om*/ if (value == null) { comp.setToolTipText(null); return comp; } comp.setToolTipText(String.valueOf(value)); if (row >= table.getRowCount()) { log.debug("row > table.getRowCount()"); return comp; } switch (column) { case TableModelForCMFolder.COL_COMPONENT_NAME: case TableModelForCMFolder.COL_LICENSE_NAME: setHorizontalAlignment(SwingConstants.LEFT); break; case TableModelForCMFolder.COL_VERSION_NAME: case TableModelForCMFolder.COL_IDENTIFIED: case TableModelForCMFolder.COL_STATUS: case TableModelForCMFolder.COL_PENDING: setHorizontalAlignment(SwingConstants.CENTER); break; } int pendingHits = 0; int identifiedHits = 0; if (table.getValueAt(row, TableModelForCMFolder.COL_PENDING) != null) { pendingHits = Tools .transStringToInteger(table.getValueAt(row, TableModelForCMFolder.COL_PENDING).toString()); } if (table.getValueAt(row, TableModelForCMFolder.COL_IDENTIFIED) != null) { identifiedHits = Tools .transStringToInteger(table.getValueAt(row, TableModelForCMFolder.COL_IDENTIFIED).toString()); } if (identifiedHits > 0 && pendingHits == 0) { comp.setFont(new Font("Arial", Font.BOLD, 12)); comp.setForeground(NORMAL_COLOR); } else if (identifiedHits == 0 && pendingHits == 0) { comp.setForeground(GRAY_COLOR); } else { comp.setForeground(NORMAL_COLOR); } return comp; }
From source file:SortableTable.java
/** * Returns the renderer component.//from w w w .ja v a 2 s .c o m * * @param table the table. * @param value the value. * @param isSelected selected? * @param hasFocus focussed? * @param row the row. * @param column the column. * @return the renderer. */ public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { if (table == null) { throw new NullPointerException("Table must not be null."); } final JComponent component; final SortableTableModel model = (SortableTableModel) table.getModel(); final int cc = table.convertColumnIndexToModel(column); final boolean isSorting = (model.getSortingColumn() == cc); final boolean isAscending = model.isAscending(); final JTableHeader header = table.getTableHeader(); final boolean isPressed = (cc == this.pressedColumn); if (this.useLabels) { final JLabel label = getRendererLabel(isSorting, isAscending); label.setText((value == null) ? "" : value.toString()); component = label; } else { final JButton button = getRendererButton(isSorting, isAscending); button.setText((value == null) ? "" : value.toString()); button.getModel().setPressed(isPressed); button.getModel().setArmed(isPressed); component = button; } if (header != null) { component.setForeground(header.getForeground()); component.setBackground(header.getBackground()); component.setFont(header.getFont()); } return component; }
From source file:net.pms.encoders.MEncoderVideo.java
@Override public JComponent config() { // Apply the orientation for the locale Locale locale = new Locale(configuration.getLanguage()); ComponentOrientation orientation = ComponentOrientation.getOrientation(locale); String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation); FormLayout layout = new FormLayout(colSpec, ROW_SPEC); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.EMPTY_BORDER); builder.setOpaque(false);//from w w w.j av a2s . co m CellConstraints cc = new CellConstraints(); checkBox = new JCheckBox(Messages.getString("MEncoderVideo.0")); checkBox.setContentAreaFilled(false); if (configuration.getSkipLoopFilterEnabled()) { checkBox.setSelected(true); } checkBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setSkipLoopFilterEnabled((e.getStateChange() == ItemEvent.SELECTED)); } }); JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(1, 1, 15), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); mencodermt = new JCheckBox(Messages.getString("MEncoderVideo.35")); mencodermt.setContentAreaFilled(false); if (configuration.getMencoderMT()) { mencodermt.setSelected(true); } mencodermt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { configuration.setMencoderMT(mencodermt.isSelected()); } }); mencodermt.setEnabled(Platform.isWindows() || Platform.isMac()); builder.add(mencodermt, FormLayoutUtil.flip(cc.xy(1, 3), colSpec, orientation)); builder.add(checkBox, FormLayoutUtil.flip(cc.xyw(3, 3, 12), colSpec, orientation)); noskip = new JCheckBox(Messages.getString("MEncoderVideo.2")); noskip.setContentAreaFilled(false); if (configuration.isMencoderNoOutOfSync()) { noskip.setSelected(true); } noskip.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderNoOutOfSync((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(noskip, FormLayoutUtil.flip(cc.xy(1, 5), colSpec, orientation)); JButton button = new JButton(Messages.getString("MEncoderVideo.29")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel codecPanel = new JPanel(new BorderLayout()); final JTextArea textArea = new JTextArea(); textArea.setText(configuration.getMencoderCodecSpecificConfig()); textArea.setFont(new Font("Courier", Font.PLAIN, 12)); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new java.awt.Dimension(900, 100)); final JTextArea textAreaDefault = new JTextArea(); textAreaDefault.setText(DEFAULT_CODEC_CONF_SCRIPT); textAreaDefault.setBackground(Color.WHITE); textAreaDefault.setFont(new Font("Courier", Font.PLAIN, 12)); textAreaDefault.setEditable(false); textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync()); JScrollPane scrollPaneDefault = new JScrollPane(textAreaDefault); scrollPaneDefault.setPreferredSize(new java.awt.Dimension(900, 450)); JPanel customPanel = new JPanel(new BorderLayout()); intelligentsync = new JCheckBox(Messages.getString("MEncoderVideo.3")); intelligentsync.setContentAreaFilled(false); if (configuration.isMencoderIntelligentSync()) { intelligentsync.setSelected(true); } intelligentsync.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderIntelligentSync((e.getStateChange() == ItemEvent.SELECTED)); textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync()); } }); JLabel label = new JLabel(Messages.getString("MEncoderVideo.33")); customPanel.add(label, BorderLayout.NORTH); customPanel.add(scrollPane, BorderLayout.SOUTH); codecPanel.add(intelligentsync, BorderLayout.NORTH); codecPanel.add(scrollPaneDefault, BorderLayout.CENTER); codecPanel.add(customPanel, BorderLayout.SOUTH); while (JOptionPane.showOptionDialog( SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), codecPanel, Messages.getString("MEncoderVideo.34"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) { String newCodecparam = textArea.getText(); DLNAMediaInfo fakemedia = new DLNAMediaInfo(); DLNAMediaAudio audio = new DLNAMediaAudio(); audio.setCodecA("ac3"); fakemedia.setCodecV("mpeg4"); fakemedia.setContainer("matroska"); fakemedia.setDuration(45d * 60); audio.getAudioProperties().setNumberOfChannels(2); fakemedia.setWidth(1280); fakemedia.setHeight(720); audio.setSampleFrequency("48000"); fakemedia.setFrameRate("23.976"); fakemedia.getAudioTracksList().add(audio); String result[] = getSpecificCodecOptions(newCodecparam, fakemedia, new OutputParams(configuration), "dummy.mpg", "dummy.srt", false, true); if (result.length > 0 && result[0].startsWith("@@")) { String errorMessage = result[0].substring(2); JOptionPane.showMessageDialog( SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), errorMessage, Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE); } else { configuration.setMencoderCodecSpecificConfig(newCodecparam); break; } } } }); builder.add(button, FormLayoutUtil.flip(cc.xy(1, 11), colSpec, orientation)); forcefps = new JCheckBox(Messages.getString("MEncoderVideo.4")); forcefps.setContentAreaFilled(false); if (configuration.isMencoderForceFps()) { forcefps.setSelected(true); } forcefps.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderForceFps(e.getStateChange() == ItemEvent.SELECTED); } }); builder.add(forcefps, FormLayoutUtil.flip(cc.xyw(1, 7, 2), colSpec, orientation)); yadif = new JCheckBox(Messages.getString("MEncoderVideo.26")); yadif.setContentAreaFilled(false); if (configuration.isMencoderYadif()) { yadif.setSelected(true); } yadif.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderYadif(e.getStateChange() == ItemEvent.SELECTED); } }); builder.add(yadif, FormLayoutUtil.flip(cc.xyw(3, 7, 7), colSpec, orientation)); scaler = new JCheckBox(Messages.getString("MEncoderVideo.27")); scaler.setContentAreaFilled(false); scaler.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderScaler(e.getStateChange() == ItemEvent.SELECTED); scaleX.setEnabled(configuration.isMencoderScaler()); scaleY.setEnabled(configuration.isMencoderScaler()); } }); builder.add(scaler, FormLayoutUtil.flip(cc.xyw(3, 5, 7), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.28"), FormLayoutUtil .flip(cc.xy(9, 5, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation)); scaleX = new JTextField("" + configuration.getMencoderScaleX()); scaleX.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { configuration.setMencoderScaleX(Integer.parseInt(scaleX.getText())); } catch (NumberFormatException nfe) { logger.debug("Could not parse scaleX from \"" + scaleX.getText() + "\""); } } }); builder.add(scaleX, FormLayoutUtil.flip(cc.xy(11, 5), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.30"), FormLayoutUtil .flip(cc.xy(13, 5, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation)); scaleY = new JTextField("" + configuration.getMencoderScaleY()); scaleY.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { configuration.setMencoderScaleY(Integer.parseInt(scaleY.getText())); } catch (NumberFormatException nfe) { logger.debug("Could not parse scaleY from \"" + scaleY.getText() + "\""); } } }); builder.add(scaleY, FormLayoutUtil.flip(cc.xy(15, 5), colSpec, orientation)); if (configuration.isMencoderScaler()) { scaler.setSelected(true); } else { scaleX.setEnabled(false); scaleY.setEnabled(false); } builder.addLabel(Messages.getString("MEncoderVideo.6"), FormLayoutUtil.flip(cc.xy(1, 13), colSpec, orientation)); mencoder_custom_options = new JTextField(configuration.getMencoderCustomOptions()); mencoder_custom_options.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderCustomOptions(mencoder_custom_options.getText()); } }); builder.add(mencoder_custom_options, FormLayoutUtil.flip(cc.xyw(3, 13, 13), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.93"), FormLayoutUtil.flip(cc.xy(1, 15), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.28") + " (%)", FormLayoutUtil .flip(cc.xy(1, 15, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation)); ocw = new JTextField(configuration.getMencoderOverscanCompensationWidth()); ocw.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderOverscanCompensationWidth(ocw.getText()); } }); builder.add(ocw, FormLayoutUtil.flip(cc.xy(3, 15), colSpec, orientation)); builder.addLabel(Messages.getString("MEncoderVideo.30") + " (%)", FormLayoutUtil.flip(cc.xy(5, 15), colSpec, orientation)); och = new JTextField(configuration.getMencoderOverscanCompensationHeight()); och.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderOverscanCompensationHeight(och.getText()); } }); builder.add(och, FormLayoutUtil.flip(cc.xy(7, 15), colSpec, orientation)); cmp = builder.addSeparator(Messages.getString("MEncoderVideo.8"), FormLayoutUtil.flip(cc.xyw(1, 17, 15), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); builder.addLabel(Messages.getString("MEncoderVideo.16"), FormLayoutUtil .flip(cc.xy(1, 27, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation)); mencoder_noass_scale = new JTextField(configuration.getMencoderNoAssScale()); mencoder_noass_scale.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderNoAssScale(mencoder_noass_scale.getText()); } }); builder.addLabel(Messages.getString("MEncoderVideo.17"), FormLayoutUtil.flip(cc.xy(5, 27), colSpec, orientation)); mencoder_noass_outline = new JTextField(configuration.getMencoderNoAssOutline()); mencoder_noass_outline.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderNoAssOutline(mencoder_noass_outline.getText()); } }); builder.addLabel(Messages.getString("MEncoderVideo.18"), FormLayoutUtil.flip(cc.xy(9, 27), colSpec, orientation)); mencoder_noass_blur = new JTextField(configuration.getMencoderNoAssBlur()); mencoder_noass_blur.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderNoAssBlur(mencoder_noass_blur.getText()); } }); builder.addLabel(Messages.getString("MEncoderVideo.19"), FormLayoutUtil.flip(cc.xy(13, 27), colSpec, orientation)); mencoder_noass_subpos = new JTextField(configuration.getMencoderNoAssSubPos()); mencoder_noass_subpos.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderNoAssSubPos(mencoder_noass_subpos.getText()); } }); builder.add(mencoder_noass_scale, FormLayoutUtil.flip(cc.xy(3, 27), colSpec, orientation)); builder.add(mencoder_noass_outline, FormLayoutUtil.flip(cc.xy(7, 27), colSpec, orientation)); builder.add(mencoder_noass_blur, FormLayoutUtil.flip(cc.xy(11, 27), colSpec, orientation)); builder.add(mencoder_noass_subpos, FormLayoutUtil.flip(cc.xy(15, 27), colSpec, orientation)); ass = new JCheckBox(Messages.getString("MEncoderVideo.20")); ass.setContentAreaFilled(false); ass.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e != null) { configuration.setMencoderAss(e.getStateChange() == ItemEvent.SELECTED); } } }); builder.add(ass, FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation)); ass.setSelected(configuration.isMencoderAss()); ass.getItemListeners()[0].itemStateChanged(null); fc = new JCheckBox(Messages.getString("MEncoderVideo.21")); fc.setContentAreaFilled(false); fc.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderFontConfig(e.getStateChange() == ItemEvent.SELECTED); } }); builder.add(fc, FormLayoutUtil.flip(cc.xyw(3, 23, 5), colSpec, orientation)); fc.setSelected(configuration.isMencoderFontConfig()); assdefaultstyle = new JCheckBox(Messages.getString("MEncoderVideo.36")); assdefaultstyle.setContentAreaFilled(false); assdefaultstyle.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setMencoderAssDefaultStyle(e.getStateChange() == ItemEvent.SELECTED); } }); builder.add(assdefaultstyle, FormLayoutUtil.flip(cc.xyw(8, 23, 4), colSpec, orientation)); assdefaultstyle.setSelected(configuration.isMencoderAssDefaultStyle()); builder.addLabel(Messages.getString("MEncoderVideo.92"), FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation)); subq = new JTextField(configuration.getMencoderVobsubSubtitleQuality()); subq.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setMencoderVobsubSubtitleQuality(subq.getText()); } }); builder.add(subq, FormLayoutUtil.flip(cc.xyw(3, 29, 1), colSpec, orientation)); configuration.addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent event) { if (event.getPropertyName() == null) { return; } if ((!event.isBeforeUpdate()) && event.getPropertyName().equals(PmsConfiguration.KEY_DISABLE_SUBTITLES)) { boolean enabled = !configuration.isDisableSubtitles(); ass.setEnabled(enabled); assdefaultstyle.setEnabled(enabled); fc.setEnabled(enabled); mencoder_noass_scale.setEnabled(enabled); mencoder_noass_outline.setEnabled(enabled); mencoder_noass_blur.setEnabled(enabled); mencoder_noass_subpos.setEnabled(enabled); ocw.setEnabled(enabled); och.setEnabled(enabled); subq.setEnabled(enabled); if (enabled) { ass.getItemListeners()[0].itemStateChanged(null); } } } }); JPanel panel = builder.getPanel(); // Apply the orientation to the panel and all components in it panel.applyComponentOrientation(orientation); return panel; }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextField.java
/** * Creates the various UI Components for the formatter. *//*from w w w . java2 s . c om*/ 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.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Creates a new label.//from w w w. jav a 2 s .co m * * @param type The type of component to create. Default type is JLabel. * @param color The foreground color if not <code>null</code>. * @return See above. */ public static JComponent createComponent(Class type, Color color) { if (type == null) type = JLabel.class; JComponent comp = null; if (JLabel.class.equals(type)) comp = new JLabel(); else if (OMETextField.class.equals(type)) comp = new OMETextField(); else if (OMETextArea.class.equals(type)) comp = new OMETextArea(); else if (NumericalTextField.class.equals(type)) { comp = new NumericalTextField(); ((NumericalTextField) comp).setHorizontalAlignment(JTextField.LEFT); ((NumericalTextField) comp).setNegativeAccepted(true); comp.setBorder(null); } if (comp == null) comp = new JLabel(); comp.setBackground(BACKGROUND_COLOR); Font font = comp.getFont(); comp.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2)); if (color != null) comp.setForeground(color); return comp; }
From source file:org.tinymediamanager.ui.movies.MovieExtendedSearchPanel.java
private void setComponentFont(JComponent comp) { comp.setFont(comp.getFont().deriveFont(FONT_SIZE)); }