Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li>This is just an example for the final question: <ul> <li>Windows 7 (green progress bar)</li> <li>JDK 1.7.0_25 (WindowsLookAndFeel)</li> </ul></li> </ul> <p><img src="https://i.stack.imgur.com/iGvtq.png" alt="TurnProgressBarRedTest "></p> <pre><code>import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.beans.*; import javax.swing.*; import javax.swing.plaf.LayerUI; public class TurnProgressBarRedTest { public JComponent makeUI() { final BoundedRangeModel model = new DefaultBoundedRangeModel(); final BlockedColorLayerUI layerUI = new BlockedColorLayerUI(); final JPanel p = new JPanel(new GridLayout(4, 1, 12, 12)); p.setBorder(BorderFactory.createEmptyBorder(24,24,24,24)); final JProgressBar pb1 = new JProgressBar(model); pb1.setStringPainted(true); p.add(pb1); final JProgressBar pb2 = new JProgressBar(model); pb2.setStringPainted(true); p.add(pb2); p.add(new JProgressBar(model)); p.add(new JLayer&lt;JProgressBar&gt;(new JProgressBar(model), layerUI)); JPanel box = new JPanel(); box.add(new JButton(new AbstractAction("+10") { private int i = 0; @Override public void actionPerformed(ActionEvent e) { model.setValue(i = (i&gt;=100) ? 0 : i + 10); } })); //http://msdn.microsoft.com/en-us/library/windows/desktop/aa511486.aspx box.add(new JCheckBox(new AbstractAction( "&lt;html&gt;Turn the progress bar red&lt;br /&gt;"+ " when there is a user recoverable condition&lt;br /&gt;"+ " that prevents making further progress.") { @Override public void actionPerformed(ActionEvent e) { boolean b = ((JCheckBox)e.getSource()).isSelected(); pb2.setForeground(b? new Color(255,0,0,100) : pb1.getForeground()); layerUI.isPreventing = b; p.repaint(); } })); JPanel panel = new JPanel(new BorderLayout()); panel.add(p, BorderLayout.NORTH); panel.add(box, BorderLayout.SOUTH); return panel; } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { createAndShowGUI(); } }); } public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new TurnProgressBarRedTest().makeUI()); f.setSize(320, 240); f.setLocationRelativeTo(null); f.setVisible(true); } } class BlockedColorLayerUI extends LayerUI&lt;JProgressBar&gt; { public boolean isPreventing = false; private BufferedImage bi; private int prevw = -1; private int prevh = -1; @Override public void paint(Graphics g, JComponent c) { if(isPreventing) { JLayer jlayer = (JLayer)c; JProgressBar progress = (JProgressBar)jlayer.getView(); int w = progress.getSize().width; int h = progress.getSize().height; if(bi==null || w!=prevw || h!=prevh) { bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); } prevw = w; prevh = h; Graphics2D g2 = bi.createGraphics(); super.paint(g2, c); g2.dispose(); Image image = c.createImage( new FilteredImageSource(bi.getSource(), new RedGreenChannelSwapFilter())); g.drawImage(image, 0, 0, null); } else { super.paint(g, c); } } } class RedGreenChannelSwapFilter extends RGBImageFilter { @Override public int filterRGB(int x, int y, int argb) { int r = (int)((argb &gt;&gt; 16) &amp; 0xff); int g = (int)((argb &gt;&gt; 8) &amp; 0xff); int b = (int)((argb ) &amp; 0xff); return (argb &amp; 0xff000000) | (g&lt;&lt;16) | (r&lt;&lt;8) | (b); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload