List of usage examples for javax.swing JComponent getFont
@Transient
public Font getFont()
From source file:Main.java
public static void copyFontAndMargins(final JTextArea target, final JComponent source) { final Insets insets = source.getInsets(); target.setFont(source.getFont()); target.setMargin(insets);/*from w w w. ja v a 2s. c om*/ }
From source file:Main.java
public static Rectangle calculateBoundsForComponent(JComponent comp, String text, int xOffset, int yOffset) { FontMetrics fm = comp.getFontMetrics(comp.getFont()); Rectangle2D bounds = fm.getStringBounds(text, comp.getGraphics()); return new Rectangle(xOffset + (int) bounds.getX(), yOffset, (int) Math.ceil(bounds.getWidth()) + (PADDING * 2), (int) Math.ceil(bounds.getHeight() + fm.getDescent()) + (PADDING * 2)); }
From source file:Main.java
/** * Returns a string abbreviated according to the length of the available space * in a component./*w w w . j a v a2 s .co m*/ * @param str A string which may need abbreviating. * @param component The component the string will be rendered in. * @return a string abbreviated according to the length of the available space */ public static String abbreviate(String str, JComponent component) { String result = ""; if (component != null) { Graphics g = component.getGraphics(); FontMetrics fm = g.getFontMetrics(component.getFont()); int stringSize = SwingUtilities.computeStringWidth(fm, str); final int border = 48; int availableWidth = component.getWidth() - border; if (stringSize > availableWidth) { final int avCharWidth = fm.charWidth('x'); final int alwaysChop = 5; final int charsToChop = alwaysChop + ((stringSize - availableWidth) / avCharWidth); final int leftPos = (str.length() - charsToChop) / 2; final int maxLength = str.length() - charsToChop; final int left = leftPos > 0 ? leftPos : 0; final int len = maxLength > left ? maxLength : left + 1; result = abbreviate(str, left, len); } else { result = str; } } return result; }
From source file:Main.java
public static String layoutComponent(JComponent c, String text, Icon icon, int iconTextGap, int verticalAlignment, int horizontalAlignment, int verticalTextAlignment, int horizontalTextAlignment, Rectangle viewRect, Rectangle iconRect, Rectangle textRect) { resetRectangles(iconRect, textRect); return SwingUtilities.layoutCompoundLabel(c, c.getFontMetrics(c.getFont()), text, icon, verticalAlignment, horizontalAlignment, verticalTextAlignment, horizontalTextAlignment, viewRect, iconRect, textRect, iconTextGap);//from w w w . j a v a 2s.co m }
From source file:Main.java
License:asdf
public Dimension getPreferredSize(JComponent c) { FontMetrics metrics = c.getFontMetrics(c.getFont()); String tipText = ((JToolTip) c).getTipText(); if (tipText == null) { tipText = ""; }/* w ww . j a va2s.com*/ Image image = new ImageIcon("yourImage").getImage(); int width = SwingUtilities.computeStringWidth(metrics, tipText); int height = metrics.getHeight() + image.getHeight(c); if (width < image.getWidth(c)) { width = image.getWidth(c); } return new Dimension(width, height); }
From source file:MyCheckBoxUI.java
public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Dimension d = b.getSize();/*from ww w.j ava 2 s . c o m*/ g.setFont(c.getFont()); FontMetrics fm = g.getFontMetrics(); g.setColor(Color.white); g.drawString("Am I a check box", 10, 10); }
From source file:MyButtonUI.java
public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; Dimension d = b.getSize();/*from w w w. j av a 2 s . c o m*/ g.setFont(c.getFont()); FontMetrics fm = g.getFontMetrics(); g.setColor(b.getForeground()); String caption = b.getText(); int x = (d.width - fm.stringWidth(caption)) / 2; int y = (d.height + fm.getAscent()) / 2; g.drawString(caption, x, y); }
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);/*from w ww .j a v a 2 s. 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 ava 2s. 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 ww. j ava2s. 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(); }