List of usage examples for javax.swing JComponent getForeground
@Transient
public Color getForeground()
From source file:Main.java
License:asdf
public void paint(Graphics g, JComponent c) { FontMetrics metrics = c.getFontMetrics(g.getFont()); g.setColor(c.getForeground()); g.drawString(((JToolTip) c).getTipText(), 1, 1); g.drawImage(new ImageIcon("yourImage").getImage(), 1, metrics.getHeight(), c); }
From source file:DnDDemo2.java
protected Transferable createTransferable(JComponent component) { String text = ((JTextComponent) component).getText(); Color color = component.getForeground(); TextColor transferable = new TextColor(text, color); return transferable; }
From source file:de.unentscheidbar.validation.swing.trigger.ChangeTriggerTest.java
@Override protected void doNotProvokeTrigger(Iterable<JComponent> components) { for (final JComponent c : components) { robot.focusAndWaitForFocusGain(c); robot.focusAndWaitForFocusGain(gui.get(dummyKey)); runInEdt(new Runnable() { @Override// w ww .j a va 2 s . co m public void run() { Color col; while ((col = new Color(rnd.nextInt())).equals(c.getForeground())) ; c.setForeground(col); c.setBackground(col); } }); } }
From source file:org.mwc.cmap.xyplot.views.XYPlotView.java
protected void bitmapToClipBoard(JComponent component) { Point size = _plotControl.getSize(); final BufferedImage img = new BufferedImage(size.x, size.y, BufferedImage.TYPE_INT_ARGB); Graphics g = img.getGraphics(); g.setColor(component.getForeground()); g.setFont(component.getFont());/*from w w w. j a v a 2 s . co m*/ component.setSize(size.x, size.y); component.paint(g); Transferable t = new Transferable() { public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.imageFlavor }; } public boolean isDataFlavorSupported(DataFlavor flavor) { if (flavor == DataFlavor.imageFlavor) return true; return false; } public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (isDataFlavorSupported(flavor)) { return img; } return null; } }; ClipboardOwner co = new ClipboardOwner() { public void lostOwnership(java.awt.datatransfer.Clipboard clipboard, Transferable contents) { } }; java.awt.datatransfer.Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.setContents(t, co); }
From source file:org.underworldlabs.swing.plaf.base.AcceleratorToolTipUI.java
public void paint(Graphics g, JComponent c) { UIUtils.antialias(g);//from w w w .j a v a2 s.c o m Font font = c.getFont(); FontMetrics metrics = c.getFontMetrics(font); Dimension size = c.getSize(); if (c.isOpaque()) { g.setColor(c.getBackground()); g.fillRect(0, 0, size.width + 20, size.height); } JToolTip toolTip = (JToolTip) c; String tipText = getTipText(toolTip); if (!MiscUtils.isNull(tipText)) { Insets insets = c.getInsets(); Rectangle paintTextR = new Rectangle(insets.left, insets.top, size.width - (insets.left + insets.right), size.height - (insets.top + insets.bottom)); Color foreground = c.getForeground(); g.setColor(foreground); g.setFont(font); g.drawString(tipText, paintTextR.x + 3, paintTextR.y + metrics.getAscent()); String acceleratorString = getAcceleratorStringForRender(toolTip); if (StringUtils.isNotBlank(acceleratorString)) { Font acceleratorFont = font.deriveFont(font.getSize() - 1f); g.setFont(acceleratorFont); g.setColor(GUIUtils.getSlightlyBrighter(foreground, 2.0f)); g.drawString(acceleratorString, paintTextR.x + 6 + metrics.stringWidth(tipText), paintTextR.y + metrics.getAscent()); } } }