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:Main.java
/** * Change the font of all the passed {@link JComponent}s to the supplied {@link Font}. * * @param font/*from ww w . ja va 2 s.co m*/ * The {@link Font} to assign to the passed {@link JComponent}s. * @param firstComponent * The first {@link JComponent} to assign the font to. * @param remainingComponents * The rest of the {@link JComponent}s to assign the font to. */ public static void changeFontOfComponents(Font font, JComponent firstComponent, JComponent... remainingComponents) { firstComponent.setFont(font); for (JComponent component : remainingComponents) { component.setFont(font); } }
From source file:Main.java
/** * Sets font of component and all of its children. * * @param component/*from ww w . ja v a 2 s . c om*/ * component to modify * @param font * new font * @param childsOnly * whether exclude component from changes or not */ public static void setFontRecursively(final JComponent component, final Font font, final boolean childsOnly) { if (!childsOnly) { component.setFont(font); } for (int i = 0; i < component.getComponentCount(); i++) { if (component.getComponent(i) instanceof JComponent) { setFontRecursively((JComponent) component.getComponent(i), font, false); } } }
From source file:Main.java
public static void setFont(JComponent component, Font font, ComponentOrientation componentOrientation) { component.setFont(font); if (component instanceof JTextField) { component.setComponentOrientation(componentOrientation); }// ww w.j a va2 s .com if (component instanceof JTextArea) { component.setComponentOrientation(componentOrientation); } if (component instanceof JTextPane) { component.setComponentOrientation(componentOrientation); } if (component instanceof JScrollPane) { for (Component cmp : component.getComponents()) { setFont((JComponent) cmp, font, componentOrientation); } } if (component instanceof JTree) { component.setComponentOrientation(componentOrientation); } if (component instanceof JComboBox) { component.setComponentOrientation(componentOrientation); JComboBox comboBox = (JComboBox) component; ((BasicComboBoxRenderer) comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.RIGHT); ((BasicComboBoxRenderer) comboBox.getRenderer()).setAutoscrolls(true); comboBox.setMaximumRowCount(20); } /* if(component instanceof JLabel) { ((JLabel)component).setHorizontalTextPosition(SwingConstants.RIGHT); }*/ if (component instanceof JPanel) { JPanel panel = (JPanel) component; if (panel.getBorder() != null && panel.getBorder() instanceof TitledBorder) { ((TitledBorder) panel.getBorder()).setTitleFont(font); panel.setComponentOrientation(componentOrientation); } for (Component cmp : component.getComponents()) { setFont((JComponent) cmp, font, componentOrientation); } } if (component instanceof JTabbedPane) { JTabbedPane tabbedPane = (JTabbedPane) component; int tabCount = tabbedPane.getTabCount(); for (int i = 0; i < tabCount; i++) { setFont((JComponent) tabbedPane.getComponentAt(i), font, componentOrientation); } } }
From source file:au.org.ala.delta.ui.image.OverlayComponentFactory.java
private void setFont(int overlayType, JComponent overlayComp) { if (overlayType == OverlayType.OLFEATURE) { overlayComp.setFont(_imageSettings.getDefaultFeatureFont()); } else if (overlayComp instanceof OverlayButton) { overlayComp.setFont(_imageSettings.getDefaultButtonFont()); } else {/* w w w . ja v a 2 s. co m*/ overlayComp.setFont(_imageSettings.getDefaultFont()); } }
From source file:co.id.app.sys.util.StringUtils.java
public static String getMakeLiner(String temp, int widLimitMetric) { if (temp == null) { return null; }//from w w w . ja va 2 s . co m String strLiner = ""; Font ft = new Font("Arial, Helvetica, sans-serif", Font.TRUETYPE_FONT, 9); JComponent jx = new JComponent() { private static final long serialVersionUID = 2792190024722186161L; }; jx.setFont(ft); FontMetrics fm = jx.getFontMetrics(ft); int strWidMetric = fm.stringWidth(temp); while (strWidMetric > 0) { char[] ch = temp.toCharArray(); if (strWidMetric > widLimitMetric) { int wChTot = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; wChTot < widLimitMetric; i++) { wChTot += fm.charWidth(ch[i]); sb.append(ch[i]); } String strWid = sb.toString(); int lastChar13 = strWid.lastIndexOf(" "); if (lastChar13 != -1) { strWid = temp.substring(0, lastChar13); strLiner = strLiner + strWid + "<br/>"; temp = temp.substring(lastChar13 + 1, temp.length()); strWidMetric = fm.stringWidth(temp); } else { strWid = temp.substring(0, strWid.length()); strLiner = strLiner + strWid + "<br/>"; temp = temp.substring(strWid.length(), temp.length()); strWidMetric = fm.stringWidth(temp); } } else { strLiner = strLiner + temp; temp = ""; strWidMetric = fm.stringWidth(temp); } } return strLiner; }
From source file:net.pms.encoders.FFmpegDVRMSRemux.java
@Override public JComponent config() { FormLayout layout = new FormLayout("left:pref, 3dlu, p, 3dlu, 0:grow", "p, 3dlu, p, 3dlu, 0:grow"); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.EMPTY_BORDER); builder.setOpaque(false);// w w w . j ava 2s. c o m CellConstraints cc = new CellConstraints(); JComponent cmp = builder.addSeparator(Messages.getString("FFmpegDVRMSRemux.1"), cc.xyw(1, 1, 5)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); builder.addLabel(Messages.getString("FFmpegDVRMSRemux.0"), cc.xy(1, 3)); altffpath = new JTextField(configuration.getFfmpegAlternativePath()); altffpath.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setFfmpegAlternativePath(altffpath.getText()); } }); builder.add(altffpath, cc.xyw(3, 3, 3)); return builder.getPanel(); }
From source file:net.pms.movieinfo.MovieInfo.java
@Override public JComponent config() { FormLayout layout = new FormLayout( "left:pref, 2dlu, p,2dlu, p,2dlu, p, 2dlu, p, 2dlu, p,2dlu, p,200dlu, pref:grow", //$NON-NLS-1$ "p, 5dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p,0:grow"); //$NON-NLS-1$ PanelBuilder builder = new PanelBuilder(layout); builder.border(Borders.EMPTY);//w w w. j av a2 s . co m builder.opaque(false); CellConstraints cc = new CellConstraints(); JComponent cmp = builder.addSeparator("MOVIE INFO CONFIG", cc.xy(1, 1)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); pluginsField = new JTextField(); pluginsField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented if (configuration.getPlugins() != null) pluginsField.setText(configuration.getPlugins()); pluginsField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { configuration.setPlugins(pluginsField.getText()); } }); builder.addLabel("Plugins to use (in prioritized order):", cc.xy(1, 3)); builder.add(pluginsField, cc.xyw(3, 3, 12)); maxNumberOfActorsField = new JSpinner(new SpinnerNumberModel()); maxNumberOfActorsField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented maxNumberOfActorsField.setValue(configuration.getMaxNumberOfActors()); maxNumberOfActorsField.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { configuration.setMaxNumberOfActors((Integer) maxNumberOfActorsField.getValue()); } }); builder.addLabel("Maximum number of actors to display:", cc.xy(1, 5)); builder.add(maxNumberOfActorsField, cc.xy(3, 5)); downloadCoverField = new JCheckBox(); downloadCoverField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented downloadCoverField.setSelected(configuration.getDownloadCover()); downloadCoverField.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { configuration.setDownloadCover(downloadCoverField.isSelected()); } }); builder.addLabel("Download cover to movie folder:", cc.xy(5, 5)); builder.add(downloadCoverField, cc.xy(7, 5)); displayInfoField = new JTextField(); displayInfoField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented if (configuration.getDisplayInfo() != null) { displayInfoField.setText(configuration.getDisplayInfoAsString()); } displayInfoField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //TODO: Needs verification logics configuration.setDisplayInfoFromString(displayInfoField.getText()); } }); builder.addLabel("DisplayInfo:", cc.xy(13, 5)); builder.add(displayInfoField, cc.xyw(14, 5, 2)); plotLineLengthField = new JSpinner(new SpinnerNumberModel()); plotLineLengthField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented plotLineLengthField.setValue(configuration.getPlotLineLength()); plotLineLengthField.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { configuration.setPlotLineLength((Integer) plotLineLengthField.getValue()); } }); builder.addLabel("Plot line length:", cc.xy(9, 5)); builder.add(plotLineLengthField, cc.xy(11, 5)); filterField = new JTextField(); filterField.setEnabled(false); // Until MovieInfoConfiguration.save() is implemented if (configuration.getFilters() != null) { filterField.setText(configuration.getFiltersAsString()); } filterField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //TODO: Needs verification logics configuration.setFiltersFromString(filterField.getText()); } }); ScanPath = new JTextField(); builder.addLabel("Filter:", cc.xy(1, 7)); builder.add(filterField, cc.xyw(3, 7, 12)); builder.addLabel("Scan path:", cc.xy(1, 9)); builder.add(ScanPath, cc.xyw(3, 9, 12)); ScanPath.setText((String) PMS.getConfiguration().getCustomProperty("movieinfo.scan_path")); JButton scan = new JButton("Scan files"); scan.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (mdb != null) { if (!mdb.isScanLibraryRunning()) { int option = JOptionPane.showConfirmDialog(LooksFrame.get(), Messages.getString("FoldTab.3") + Messages.getString("FoldTab.4"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { mdb.scanLibrary(ScanPath.getText()); } } else { int option = JOptionPane.showConfirmDialog(LooksFrame.get(), Messages.getString("FoldTab.10"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { mdb.stopScanLibrary(); } } } } }); builder.add(scan, cc.xy(1, 11)); return builder.getPanel(); }
From source file:net.pms.encoders.AviSynthFFmpeg.java
@Override protected JComponent config(String languageLabel) { FormLayout layout = new FormLayout("left:pref, 0:grow", "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu"); PanelBuilder builder = new PanelBuilder(layout); builder.border(Borders.EMPTY);//from w w w. j a v a 2s. c o m builder.opaque(false); CellConstraints cc = new CellConstraints(); JComponent cmp = builder.addSeparator(Messages.getString(languageLabel), cc.xyw(2, 1, 1)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); multithreading = new JCheckBox(Messages.getString("MEncoderVideo.35"), configuration.isFfmpegAviSynthMultithreading()); multithreading.setContentAreaFilled(false); multithreading.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setFfmpegAviSynthMultithreading(e.getStateChange() == ItemEvent.SELECTED); } }); builder.add(GuiUtil.getPreferredSizeComponent(multithreading), cc.xy(2, 3)); interframe = new JCheckBox(Messages.getString("AviSynthMEncoder.13"), configuration.getFfmpegAvisynthInterFrame()); interframe.setContentAreaFilled(false); interframe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { configuration.setFfmpegAvisynthInterFrame(interframe.isSelected()); if (configuration.getFfmpegAvisynthInterFrame()) { JOptionPane.showMessageDialog( SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), Messages.getString("AviSynthMEncoder.16"), Messages.getString("Dialog.Information"), JOptionPane.INFORMATION_MESSAGE); } } }); builder.add(GuiUtil.getPreferredSizeComponent(interframe), cc.xy(2, 5)); interframegpu = new JCheckBox(Messages.getString("AviSynthMEncoder.15"), configuration.getFfmpegAvisynthInterFrameGPU()); interframegpu.setContentAreaFilled(false); interframegpu.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setFfmpegAvisynthInterFrameGPU((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(interframegpu), cc.xy(2, 7)); convertfps = new JCheckBox(Messages.getString("AviSynthMEncoder.3"), configuration.getFfmpegAvisynthConvertFps()); convertfps.setContentAreaFilled(false); convertfps.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setFfmpegAvisynthConvertFps((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(GuiUtil.getPreferredSizeComponent(convertfps), cc.xy(2, 9)); configuration.addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent event) { if (event.getPropertyName() == null) { return; } if ((!event.isBeforeUpdate()) && event.getPropertyName().equals(PmsConfiguration.KEY_GPU_ACCELERATION)) { interframegpu.setEnabled(configuration.isGPUAcceleration()); } } }); return builder.getPanel(); }
From source file:au.org.ala.delta.ui.image.OverlayComponentFactory.java
/** * Returns a JComponent suitable for displaying an overlay on an image * illustrating the supplied owner.//from ww w . ja v a 2s. com * * @param overlay * describes the type of overlay to create. * @param imageOwner * the Character/Item that is being Illustrated. * @return a component capable of displaying the ImageOverlay. */ public JComponent createOverlayComponent(ImageOverlay overlay, Image image) { Illustratable imageOwner = image.getSubject(); JComponent component = null; String text = _textBuilder.getText(overlay, imageOwner); switch (overlay.type) { case OverlayType.OLHEADING: // Using heading string for the data-set case OverlayType.OLTEXT: // Use a literal text string case OverlayType.OLITEM: // Use name of the item component = new RichTextLabel(overlay, text); component.setFont(_imageSettings.getDefaultFont()); break; case OverlayType.OLFEATURE: // Use name of the character component = new RichTextLabel(overlay, text); component.setFont(_imageSettings.getDefaultFeatureFont()); break; case OverlayType.OLUNITS: // Use units (for numeric characters) component = new RelativePositionedTextOverlay(overlay, text); break; case OverlayType.OLSTATE: // Use name of the state (selectable) case OverlayType.OLKEYWORD: // Use specified keyword(s) component = new SelectableTextOverlay(overlay, text); component.setFont(_imageSettings.getDefaultFeatureFont()); break; case OverlayType.OLVALUE: // Use specified values or ranges (selectable) String minVal = overlay.minVal; String maxVal = overlay.maxVal; if (StringUtils.isNotEmpty(maxVal)) { text = minVal + " - " + maxVal; } else { text = minVal; } component = new SelectableTextOverlay(overlay, text); component.setFont(_imageSettings.getDefaultFeatureFont()); break; case OverlayType.OLENTER: // Create edit box for data entry component = new TextFieldOverlay(overlay); break; case OverlayType.OLOK: // Create OK pushbutton case OverlayType.OLCANCEL: // Create Cancel pushbutton case OverlayType.OLNOTES: // Create Notes pushbutton (for character // notes) case OverlayType.OLIMAGENOTES: // Create Notes pushbutton (for notes // about the image) component = new OverlayButton(overlay, text); component.setFont(_imageSettings.getDefaultButtonFont()); break; case OverlayType.OLCOMMENT: // Not a "real" overlay type, but used to // save comments addressed // to images rather than overlays case OverlayType.OLBUTTONBLOCK: // Used only when modifying aligned // push-buttons case OverlayType.OLHOTSPOT: // Not a "real" overlay type; used for // convenience in editing case OverlayType.OLNONE: // Undefined; the remaining values MUST // correspond with array OLKeywords. case OverlayType.OLSUBJECT: // Has text for menu entry case OverlayType.OLSOUND: // Has name of .WAV sound file break; default: System.out.println("Unsupported overlay type: " + overlay.type); } if (component != null) { setFont(overlay.type, component); } return component; }
From source file:com.limegroup.gnutella.gui.LicenseWindow.java
protected void createValid() { GridBagConstraints c = new GridBagConstraints(); JComponent label = new JLabel(getDetailsString()); Font f = label.getFont();/*from w w w .j av a 2s . co m*/ label.setFont(new Font(f.getName(), Font.BOLD, f.getSize())); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.NORTHWEST; DETAILS.add(label, c); JTextArea text = newTextArea(LICENSE.getLicenseDescription(URN)); c.gridwidth = GridBagConstraints.RELATIVE; c.gridheight = 2; c.weighty = 1; c.weightx = .7; c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; DETAILS.add(text, c); if (LICENSE.getLicenseDeed(URN) != null) { label = new URLLabel(LICENSE.getLicenseDeed(URN), getDeedString()); } else { label = new JLabel(); label.setVisible(false); } c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 1; c.weighty = 0; c.weightx = .3; c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(0, 0, 3, 0); DETAILS.add(label, c); label = new URLLabel(LICENSE.getLicenseURI(), getVerificationString()); DETAILS.add(label, c); }