Colors in JProgressBars

Hi all,
I'm am able to set the color of my progress bars via setForeground() and setBackground(). However, I have been unable so far to figure out how to set the color of the String value in the progress bar (which is activated by setStringPainted(true). Does anyone have any suggestions? Thanks!
Brent

Glancing at the source code for BasicProgressBarUI there seems to be two Color variables that control the color of the String:
    // The "selectionForeground" is the color of the text when it is painted
    // over a filled area of the progress bar. The "selectionBackground"
    // is for the text over the unfilled progress bar area.
    private Color selectionForeground, selectionBackground;The values of these come from the UIManager defaults:
     selectionForeground = UIManager.getColor("ProgressBar.selectionForeground");
     selectionBackground = UIManager.getColor("ProgressBar.selectionBackground");

Similar Messages

  • JProgressBar background color does not work in XP with JRE 1.4.2

    Hi,
    I am setting the background color of JProgressBar. While it used to work in 1.4.1, the background color does not show in 1.4.2 on XP. It looks like it has something to do with the XP L&F in 1.4.2. I am setting the L&F to systemlookand feel. Is anyone aware of anyworkaround for this? Setting the opaque property does not help either. I don't want to say swing.xp=false. We need the xp look and feel.
    Any help will be appreciated.
    Thanks.
    Sujatha.

    Actually I draw a blank looking into it a bit deeper. The Windows UI paintXPBackground method is private and the XPStyle class can not be accessed outside the package. I guess the reason for this is to protect the XP LAF from having the backgrounds changed etc.
    If it is important to you the source is available for you to replicate your own MyXPStyle class and then you would have to recreate the whole paintDeterminate methods in your MyProgressBarUI class. It would not be very future proof though.

  • [JProgressBar][Look&feel] Change the color

    I want to change the color of my JProgressBar :
    I have tried :
    UIManager.put("ProgressBar.foreground", new ColorUIResource(255, 0, 0));
    progressBar.updateUI();
    and
    progressBar.setForeground(Color.RED);[b]
    When I use the default look&feel, it works but with a custom look&feel (com.birosoft.liquid.LiquidLookAndFeel), the color isn't changed.
    Does anybody has an idea ?
    thanks in advance
    sylvain_2020

    hi,
    you're right but when I do :
    <b>this.progressBar.setForeground(Color.RED);
    this.progressBar.updateUI();</b>
    Nothing changes. I found that the probleme comes from the look & feel that I used since the color is changed when I don't specify any look and feel ...
    Do you know how I could resolve this ?
    Sylvain

  • JProgressBar Color Help Needed

    Greetings,
    I am attempting to find the simplest way to set the color of the text that represents the percent done in a task on a determinate progress bar. This is the font color of the element enabled by using the method "aProgBar".setStringPainted(true) command. I have found the setForeground and Background Colors. Which changed the bg of the bar or the color of the rectangle being built. But I have been unsuccesful at getting the text color to change.
    I have attempted to use some examples of customizing the defaultUi settings. However I stopped the attempt after it became a bit to long winded in its code. Plus I'm not really sure but it sounds like if I change the UIDefaults it would be a global change so every progress bar would now look the same. In this case I could do that due to the fact that I only have 2 bars in the application and it would be alright. However I am confident that there is a way to customize I single instance of this. I just dont know how to do it.
    I am a middleware developer that rarely gets the chance to use Swing so I always find myself having to learn from scratch almost everything each time I do it. Any advice on training or books that might help me retain or improve my development time would also be appreceated. In general are there any basics that I should study that would allow me to understand core principles throughout awt/Swing. Ie "here is the framwork that runs throughout Awt or Swing that controls Look and feel of most components and it's name is _________".
    Anyhow thanks in advance.
    B.

    Michael,
    Thanks for your reply as well. This solution works and works simply. I do believe I just change all instances of JProgress to now show the same custom colors. Which is ok by me.
    The key phrase in this solution is the phrase "prior to construction". I simply set it in a static init block and went from there. You might be able to do something right prior to creating a new instance to keep this effecting only one instance. I have not tried.
    Thanks agian for providing a single line solution and the proper level of detail in order to get it to work.

  • JProgressBar in a JDialog ?

    I wished to display my progress bar in a JDialog.
    I tried adding the progress bar to an independent JDialog and displayed it and
    it seemed to work.
    But I wanted a modal JDialog to be part of the JFrame of my application while
    showing the progress. This time neither the progress bar that was added is showing up
    nor it is getting updated !!
    How is this typically implemented ?
    It will be great to see a reply from the Swing gurus around so that I complete my application
    in a style!
    Thanks in advance.

    Hi,
    I have the same problem. I am trying to add a JProgressBar to a JDialog. I add the timer for the progressbar before the dialog is made visible. But my progressbar fails to display.
    A part of my code to illustrate my procedure --
    public class ClusterProgressDialog extends JDialog {
        JProgressBar progressBar;
        JLabel currentProcessLabel;
        Timer timer;
        final ClusterProcess clusterProcess;
        public ClusterProgressDialog(Frame parent, String title,
                ClusterProcess process) {
            super(parent, title, false);
            setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            clusterProcess = process;
            currentProcessLabel = new JLabel();
            currentProcessLabel.setBackground(Color.WHITE);
            initialize(parent);
            setVisible(true);
        public void initialize(Frame parent) {
            setSize(300, 100);
            if (!Platform.isMac())
                setBackground(Color.WHITE);
            progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            timer = new Timer(100, new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    progressBar.setValue((progressBar.getMaximum() - clusterProcess
                            .getClusterCount()));
                    if (clusterProcess.isDone()) {
                        Toolkit.getDefaultToolkit().beep();
                        timer.stop();
                        setVisible(false);
                        dispose();
            JPanel contentPane = new JPanel();
            contentPane.setLayout(new BorderLayout());
            contentPane.add(currentProcessLabel, BorderLayout.NORTH);
            contentPane.add(progressBar, BorderLayout.CENTER);
            Border border = BorderFactory.createMatteBorder(10, 10, 10, 10,
                    Color.WHITE);
            contentPane.setBorder(border);
            setContentPane(contentPane);
        public void setLimits(int min, int max) {
            progressBar.setIndeterminate(false);
            progressBar.setMinimum(min);
            progressBar.setMaximum(max);
            progressBar.setValue(min);
            progressBar.setStringPainted(true);
        public void startTimer() {
            timer.start();
    }I reuse the progress bar, alternating it between indeterminate and determinate states for different functions in my process being monitored.
    Can anyone help me in this?

  • How to change the color of the progress bar and string

    Is their anyway to change the color of the progress bar and the string which shows the progress of the bar. The current color of the bar is purple and i would like it to be red or blue so that it stands out against the background of the JFrame i am using. I dont want to change the color of the JFrame
    Thanks in advance

    import java.awt.*;
    import javax.swing.*;
    public class ProgressEx {
        public static void main(String[] args) {
            UIManager.put("ProgressBar.background", Color.WHITE);
            UIManager.put("ProgressBar.foreground", Color.BLACK);
            UIManager.put("ProgressBar.selectionBackground", Color.YELLOW);
            UIManager.put("ProgressBar.selectionForeground", Color.RED);
            UIManager.put("ProgressBar.shadow", Color.GREEN);
            UIManager.put("ProgressBar.highlight", Color.BLUE);
            JFrame f = new JFrame("Test");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JProgressBar pb1 = new JProgressBar();
            pb1.setStringPainted(true);
            pb1.setValue(50);
            JProgressBar pb2 = new JProgressBar();
            pb2.setIndeterminate(true);
            Container cp = f.getContentPane();
            cp.add(pb1, BorderLayout.NORTH);
            cp.add(pb2, BorderLayout.SOUTH);
            f.pack();
            f.setVisible(true);
    }

  • Is it possible to define a range for JProgressBar ??

    I want to set a range on JProgressBar. Let's say I want to set red color for "30%" of progress bar to "70%" of progress bar.
    If i do:
    JProgressBar progressBar= new JProgressBar(JProgressBar.HORIZONTAL);
              progressBar.setBackground(Color.yellow);
              progressBar.setForeground(Color.red);
              progressBar.setMinimum(0);
              progressBar.setMaximum(100);
              progressBar.setValue(30);
    // it will paint till 30% of the bar.
    progressBar.setValue(70);
    // it will paint from beginning of bar to 70% of the bar.
    Is it possible to paint from value 30 to value 70. (is it possible to do it my defining our own class which extends from JProgressBar ??? I tried but was not successful)
    any help would be appreciated.
    regards,
    Kumar

    Hi,
    try this ;-)
    JProgressBar progress;
    public synchronized void addProgress (int newValue) {
       for (int i=progress.getValue(); i<=newValue; i++)  {
          progress.setValue(i);
          try  { Thread.sleep(20);  }
           catch (InterruptedException e)  { }
        progress.setString (newValue + " %");
    }

  • Multiple colors in cfgridcolumn

    I need to display two different colors in a cfgridcolumn if
    the due date is less than the current date; for example, black
    color in the due date and red color in the number of past due day.
    I tried to use setStyle and setPropertiesAt function to change the
    color; however, I do not have luck. Anyone has ideas to set two
    colors in one grid column?
    01/12/2003 (1354 days past due)
    10/20/2006
    Thanks,
    Daniel

    Have a close look at the BasicProgressBarUI class in the Swing source code.
    (The source code can be found in your <java-home> directory in src.zip)
    You can extend this class, and override the paintDeterminate(Graphics, JComponent) method to alter the drawing of the progress bar. This may do what you need. Eg.
    public class MyProgressBarUI extends BasicProgressBarUI
      protected void paintDeterminate(Graphics g, JComponent c)
        // your painting code here
    Also, then set this into your JProgressBar component like so:
    JProgressBar pb = new JProgressBar( );
    pb.setUI( new MyProgressBarUI( ) );
    - Paul

  • JProgressBar Shows Up Too Late--How Do I Update the Display Immediately?

    My application has a split pane, the bottom page of which is a panel containing an image that takes a long time to load. For that reason, I want the bottom pane to be a panel with a progress bar until the image is ready.
    Here's a simple version of my code:
    JPanel progressBarPanel = new JPanel();
    JProgressBar progressBar = new JProgressBar(0, 1);
    progressBar.setIndeterminate(true);
    progressBarPanel.add(progressBar);
    splitPane.setBottomComponent(progressBarPanel);  // line A
    splitPane.invalidate();
    JPanel imagePanel = createImagePanelSlowly();  // line B
    splitPane.setBottomComponent(imagePanel);
    splitPane.invalidate();However, this doesn't work; the display isn't updated until the image is ready. What do I need to put in between lines A and B so that the progress bar shows up before line B starts executing? I've tried validate(), repaint(), using threads and setting the size of the frame to zero and back again, but none of those seem to work. If I pop up a dialog after I add the progress bar to the split pane, the progress bar shows up as soon as the dialog shows up.
    This code is inside a ListSelectionListener on a table elsewhere on the GUI, in case that's relevant.
    I think I don't understand some basic principle about how to get the GUI to be updated immediately after I make some change.

    As suggested, I have prepared a compilable demonstration. I figured out that the
    problem I was having before was that I was trying to join the background and
    event-processing threads (I had been using threads, but I didn't show that code in the
    version I posted since it didn't seem to matter). After I eliminated the join, the progress
    bar is displayed, but the user can do other things while the image is loading. I want to
    prevent the user from doing that. I switched the cursor to a wait cursor, but that doesn't
    seem to prevent it.
    In particular, while it is loading, the user should be able to:
    * resize the window
    * minimize the window and bring it back up
    * ideally, adjust the split pane, but that isn't critical
    but NOT:
    * select a different row in the table
    * sort the table
    * use the menus
    Any attempt by the user to perform the disallowed actions should have no effect either
    while the image is loading or after it has finished.
    (That is, the disallowed events should not simply be queued for later.)
    I wonder if there is a simple way to accomplish that.
    Here is a demo (3 classes):
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Cursor;
    import java.awt.Font;
    import java.awt.GraphicsEnvironment;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Enumeration;
    import java.util.Vector;
    import javax.swing.Box;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.JScrollPane;
    import javax.swing.JSplitPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.UIManager;
    import javax.swing.border.Border;
    import javax.swing.border.EtchedBorder;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableColumn;
    * <p>Copyright (C) 2006
    * <p>All rights reserved.
    public class DisableGUIDemo extends JFrame {
         static final Rectangle SCREEN_SIZE = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
         static final Color HYACINTH = new Color(160, 96, 192);
         static final Color LAVENDER = new Color(224, 208, 232);
         Vector<Vector<String>> demoTableData = new Vector<Vector<String>>();
         Vector<String> demoColumnNames = new Vector<String>();
         protected JTable dataTable;
         protected JScrollPane tablePane;
         protected JSplitPane mainPane;
         protected JPanel imageArea;
         private DefaultTableModel dataModel;
          * This creates a new <code>DisableGUIDemo</code> instance, builds the UI
          * components and displays them.
         private DisableGUIDemo(){
              super();
              setTitle("Demo");
              // Ugly:  Initialize the table with demo data.
              Vector<String> demoTableFirstRow = new Vector<String>();
              demoTableFirstRow.add("18");
              demoTableFirstRow.add("13");
              demoTableFirstRow.add("11");
              demoTableFirstRow.add("19");
              demoTableFirstRow.add("19");
              demoTableData.add(demoTableFirstRow);
              Vector<String> demoTableSecondRow = new Vector<String>();
              demoTableSecondRow.add("5");
              demoTableSecondRow.add("3");
              demoTableSecondRow.add("4");
              demoTableSecondRow.add("1");
              demoTableSecondRow.add("3");
              demoTableData.add(demoTableSecondRow);
              Vector<String> demoTableThirdRow = new Vector<String>();
              demoTableThirdRow.add("11");
              demoTableThirdRow.add("12");
              demoTableThirdRow.add("10");
              demoTableThirdRow.add("18");
              demoTableThirdRow.add("18");
              demoTableData.add(demoTableThirdRow);
              demoColumnNames.add("Column 0");
              demoColumnNames.add("Column 1");
              demoColumnNames.add("Column 2");
              demoColumnNames.add("Column 3");
              demoColumnNames.add("Column 4");
              dataModel = new DefaultTableModel(demoTableData, demoColumnNames);
              initialize(); 
          * The <code>initialize</code> method builds and displays up the GUI.
         private void initialize() {
              addWindowListener(new WindowAdapter()  {
                        public void windowClosing(WindowEvent e)  {
                             System.exit(0);
              // Build the GUI panels.
              setJMenuBar(menuBar());
              createSplitPane(true);
              setLocation(SCREEN_SIZE.x, SCREEN_SIZE.y);
              setSize(SCREEN_SIZE.width, SCREEN_SIZE.height - 20);
              setVisible(true); 
          * This creates and returns the menu bar.  The actions to take in response to menu-option selections are
          * specified here.
          * @return the menu bar
         private JMenuBar menuBar(){
              JMenuBar menuBar = new JMenuBar();
              JMenu fileMenu = new JMenu("File");
              fileMenu.setFont(fileMenu.getFont().deriveFont(10.0f));
              JMenuItem reset = new JMenuItem("Reset");
              reset.setFont(reset.getFont().deriveFont(10.0f));
              reset.addActionListener(new ActionListener(){
                        // When the user resets the display, the configuration panel is recreated.
                        public void actionPerformed(ActionEvent e){
                             dataModel = new DefaultTableModel(demoTableData, demoColumnNames);
                             createSplitPane(true);
                             int oldWidth = getWidth();
                             int oldHeight = getHeight();
                             setSize(0, 0);
                             setSize(oldWidth, oldHeight);
                             repaint();
                             JOptionPane.showMessageDialog(DisableGUIDemo.this,
                                                                                                        "The display should be reset.",
                                                                                                        "Reset",
                                                                                                        JOptionPane.PLAIN_MESSAGE);
              fileMenu.add(reset);
              fileMenu.addSeparator();
              JMenuItem saveTable = new JMenuItem("Save Table");
              saveTable.setFont(saveTable.getFont().deriveFont(10.0f));
              saveTable.setEnabled(false);
              fileMenu.add(saveTable);
              menuBar.add(fileMenu);
              menuBar.add(Box.createHorizontalGlue());
              JMenu helpMenu = new JMenu("Help");
              helpMenu.setFont(helpMenu.getFont().deriveFont(10.0f));
              JMenuItem help = new JMenuItem("Documentation");
              help.setFont(help.getFont().deriveFont(10.0f));
              help.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                             JOptionPane.showMessageDialog(DisableGUIDemo.this, "There is no documentation available for the demo.");
              helpMenu.add(help);
              menuBar.add(helpMenu);
              return menuBar;
          * The <code>createSplitPane</code> method creates the table and image area and displays them in a split pane.
          * @param createNewTable whether to create a new table (should be false if the table has already been created)
         private void createSplitPane(boolean createNewTable){
              if (createNewTable){
                   dataTable = dataTable();
                   tablePane = new JScrollPane(dataTable);
                   Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, LAVENDER, HYACINTH);
                   tablePane.setBorder(etchedBorder);
              int tablePaneWidth = tablePane.getPreferredSize().width;
              int selectedRow = dataTable.getSelectedRow();
              imageArea
                   = (selectedRow == -1)
                   ? new JPanel()
                   : imageArea((String) dataTable.getValueAt(selectedRow, 0),
                                                 (String) dataTable.getValueAt(selectedRow, 2));
              imageArea.setMinimumSize(imageArea.getPreferredSize());
              mainPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tablePane, imageArea);
              getContentPane().removeAll();
              getContentPane().add(mainPane);
          * The <code>dataTable</code> method returns the data table.
          * @return the data table
         private JTable dataTable(){
              JTable table = new JTable(dataModel);
              table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              ListSelectionModel rowSM = table.getSelectionModel();
              rowSM.addListSelectionListener(new ListSelectionListener() {
                        public void valueChanged(ListSelectionEvent e) {
                             if (e.getValueIsAdjusting()){
                                  return;  // Ignore extra events.
                             ListSelectionModel lsm =
                (ListSelectionModel) e.getSource();
                             if (! lsm.isSelectionEmpty()){
                                  final int selectedRow = dataTable.getSelectedRow();
                                  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                                  JPanel progressBarPanel = new JPanel();  // This should have a border layout.
                                  JProgressBar progressBar = new JProgressBar(0, 1);
                                  progressBar.setIndeterminate(true);
                                  progressBarPanel.add(progressBar);
                                  mainPane.setBottomComponent(progressBarPanel);
                                  mainPane.invalidate();
                                  mainPane.validate();
                                  Thread backgroundThread = new Thread(){
                                            public void run(){
                                                 JPanel imageDisplay = imageArea((String) dataTable.getValueAt(selectedRow, 0),
                                                                                                                                 (String) dataTable.getValueAt(selectedRow, 2));
                                                 mainPane.setBottomComponent(imageDisplay);
                                                 mainPane.invalidate();
                                                 setCursor(null);
                                  backgroundThread.start();
                                  // The following code, before being commented out, caused the GUI to be unresponsive while the image was
                                  // being loaded.  However, without it, the user can do other things while the image is loading, which is
                                  // not desired.
    //                               try{
    //                                    backgroundThread.join();
    //                               catch (InterruptedException ie){
    //                                    // N/A
              if (dataModel != null){
                   table.sizeColumnsToFit(-1);
                   table.getTableHeader().setReorderingAllowed(false);
                   SpecialHeaderRenderer headerRenderer = new SpecialHeaderRenderer(this);
                   SpecialCellRenderer bodyCellRenderer = new SpecialCellRenderer();
                   int i = 0;
                   for (Enumeration<TableColumn> columns = table.getColumnModel().getColumns(); columns.hasMoreElements(); /** */){
                        int columnWidth = 0;
                        TableColumn nextColumn = columns.nextElement();
                        nextColumn.setHeaderRenderer(headerRenderer);
                        nextColumn.setCellRenderer(bodyCellRenderer);
                        nextColumn.sizeWidthToFit();
                        Component comp = headerRenderer.getTableCellRendererComponent(table, nextColumn.getHeaderValue(),
                                                                                                                                                                                   false, false, 0, 0);
                        columnWidth = comp.getPreferredSize().width;
                        for (int j = 0; j < dataModel.getRowCount(); j++){
                             comp = table.getCellRenderer(j, i).getTableCellRendererComponent(table, dataModel.getValueAt(j, i),
                                                                                                                                                                                              false, false, j, i);
                             columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
                        nextColumn.setPreferredWidth(columnWidth);
                        nextColumn.setMinWidth(columnWidth);
                        i++;
              return table;
          * The <code>imageArea</code> method returns a panel in which an image is shown in the real application.
          * In the demo application, it is replaced by a text label; an artificial delay is used to simulate the
          * delay that would occur during image loading.  The image is loaded when the user selects a row in the table.
          * @param parameter1 a parameter to image creation
          * @param parameter2 a parameter to image creation
          * @return a panel in which a text label stands in for an image
         private JPanel imageArea(String parameter1, String parameter2){
              try{
                   Thread.sleep(3000);
              catch (InterruptedException ie){
                   // N/A
              JPanel imagePanel = new JPanel();
              JLabel substituteLabel = new JLabel("Image for " + parameter1 + ", " + parameter2);
              imagePanel.add(substituteLabel);
              return imagePanel;
          * @param args
         public static void main (String[] args) {
              UIManager.put("Table.font", new Font("DialogInput", Font.PLAIN, 10));
              UIManager.put("Label.font", new Font("Dialog", Font.BOLD, 10));
              UIManager.put("TextField.font", new Font("DialogInput", Font.PLAIN, 10));
              UIManager.put("ComboBox.font", new Font("Dialog", Font.BOLD, 10));
              UIManager.put("Button.font", new Font("Dialog", Font.BOLD, 10));
              UIManager.put("List.font", new Font("Dialog", Font.BOLD, 10));
              try {           
                   new DisableGUIDemo();
              catch (Throwable e) {
                   e.printStackTrace();
                   System.exit(0);
         } // end of main ()
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Font;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridLayout;
    import java.awt.Insets;
    import java.awt.Rectangle;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Comparator;
    import java.util.TreeSet;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.SwingConstants;
    import javax.swing.UIManager;
    import javax.swing.border.EmptyBorder;
    import javax.swing.table.TableCellRenderer;
    * <p>Copyright (C) 2006
    * <p>All rights reserved.
    public class SpecialHeaderRenderer extends JPanel implements TableCellRenderer {
         static final Color MAUVE = new Color(192, 160, 208);
         static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0);
         static final EmptyBorder EMPTY_BORDER = new EmptyBorder(ZERO_INSETS);
         private GridBagConstraints constraints = new GridBagConstraints();
         final TreeSet<MouseEvent> processedEvents = new TreeSet<MouseEvent>(new Comparator<MouseEvent>(){
              public int compare(MouseEvent o1, MouseEvent o2){
                   return o1.hashCode() - o2.hashCode();
         final private JFrame owner;
      public SpecialHeaderRenderer(JFrame ownerWindow) {
        setOpaque(true);
        setForeground(Color.BLACK);
              setBackground(MAUVE);
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
              setLayout(new GridBagLayout());
              constraints.fill = GridBagConstraints.NONE;
              constraints.gridx = 0;
              setAlignmentY(Component.CENTER_ALIGNMENT);
              owner = ownerWindow;
      public Component getTableCellRendererComponent(final JTable table, Object value, boolean isSelected,
                                                                                                                             boolean hasFocus, int row, final int column){
              if (table != null){
                   removeAll();
                   String valueString = (value == null) ? "" : value.toString();
                   JLabel title = new JLabel(valueString);
                   title.setHorizontalAlignment(SwingConstants.CENTER);
                   title.setFont(title.getFont().deriveFont(12.0f));
                   constraints.gridy = 0;
                   constraints.insets = ZERO_INSETS;
                   add(title, constraints);
                   final JPanel buttonPanel = new JPanel();
                   buttonPanel.setLayout(new GridLayout(1, 2));
                   buttonPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
                   buttonPanel.setBackground(MAUVE);
                   final JButton sortAscendingButton = new JButton("V");
                   sortAscendingButton.setMargin(ZERO_INSETS);
                   sortAscendingButton.setBorder(EMPTY_BORDER);
                   constraints.gridy = 1;
                   constraints.insets = new Insets(5, 0, 0, 0);
                   buttonPanel.add(sortAscendingButton);
                   final JButton sortDescendingButton = new JButton("^");
                   sortDescendingButton.setMargin(ZERO_INSETS);
                   sortDescendingButton.setBorder(EMPTY_BORDER);
                   buttonPanel.add(sortDescendingButton);
                   add(buttonPanel, constraints);
                   table.getTableHeader().addMouseListener(new MouseAdapter(){
                             public void mouseClicked(MouseEvent e) {
                                  Rectangle panelBounds = table.getTableHeader().getHeaderRect(column);
                                  Rectangle buttonPanelBounds = buttonPanel.getBounds();
                                  Rectangle buttonBounds = sortAscendingButton.getBounds();
                                  buttonBounds.translate(buttonPanelBounds.x, buttonPanelBounds.y);
                                  buttonBounds.translate(panelBounds.x, panelBounds.y);
                                  if (buttonBounds.contains(e.getX(), e.getY()) && processedEvents.add(e)){
                                       // The click was on this button and has not yet been processed.
                                       JOptionPane.showMessageDialog(owner,
                                                                                                                  "The table would be sorted in ascending order of column " + column + ".",
                                                                                                                  "Sorted Ascending",
                                                                                                                  JOptionPane.PLAIN_MESSAGE);
                                       table.invalidate();
                                       table.revalidate();
                                       table.repaint();
                                  buttonBounds = sortDescendingButton.getBounds();
                                  buttonBounds.translate(buttonPanelBounds.x, buttonPanelBounds.y);
                                  buttonBounds.translate(panelBounds.x, panelBounds.y);
                                  if (buttonBounds.contains(e.getX(), e.getY()) && processedEvents.add(e)){
                                       // The click was on this button and has not yet been processed.
                                       JOptionPane.showMessageDialog(owner,
                                                                                                                  "The table would be sorted in descending order of column " + column + ".",
                                                                                                                  "Sorted Descending",
                                                                                                                  JOptionPane.PLAIN_MESSAGE);
                                       table.invalidate();
                                       table.revalidate();
                                       table.repaint();
              return this;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.util.HashMap;
    import javax.swing.BorderFactory;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.SwingConstants;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.LineBorder;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    * <code>SpecialCellRenderer</code> is the custom renderer for all
    * rows except the header row.
    * <p>Copyright (C) 2006
    * <p>All rights reserved.
    public class SpecialCellRenderer extends JPanel implements TableCellRenderer {
         protected Color backgroundColor = Color.PINK; // This means the rows for the first row will be white.
         protected HashMap<Object, Color> rowColors = new HashMap<Object, Color>();
      public SpecialCellRenderer(){
        setOpaque(true);
        setForeground(Color.BLACK);
              setBackground(Color.WHITE);
              setFont(new Font("Monospaced", Font.PLAIN, 10));
              setAlignmentX(Component.RIGHT_ALIGNMENT);
              setBorder(new EmptyBorder(0, 2, 0, 2));
      public Component getTableCellRendererComponent(final JTable table, Object value, boolean isSelected,
                                                                                                                             boolean hasFocus, final int row, final int column){
              String columnName = table.getColumnName(column);
              JLabel text = new JLabel();
              text.setOpaque(true);
              if (table != null){
                   DefaultTableModel model = (DefaultTableModel) table.getModel();
                   if (model == null){
                        System.out.println("The model is null!!");
                        System.exit(1);
                   if (table.isCellSelected(row, column)){
                        setBorder(BorderFactory.createMatteBorder((column < 2) ? 0 : 1,
                                                                                                                                 (column == 2) ? 1 : 0,
                                                                                                                                 (column < 2) ? 0 : 1,
                                                                                                                                 (column == table.getColumnCount() - 1) ? 1 : 0,
                                                                                                                                 Color.BLUE));
                   else{
                        setBorder(BorderFactory.createEmptyBorder());
                   final String rowIdentifier = (String) model.getValueAt(row, 0);
                   if (! rowColors.containsKey(rowIdentifier)){
                        rowColors.put(rowIdentifier, nextBackgroundColor());
                   text.setBackground(rowColors.get(rowIdentifier));
                   text.setFont(getFont().deriveFont(Font.PLAIN));
                   String valueString = (value == null) ? "" : value.toString();
                   text.setText(valueString);
                   try{
                        Double.parseDouble(valueString);
                        text.setHorizontalAlignment(SwingConstants.TRAILING);
                   catch (NumberFormatException nfe){
                        text.setHorizontalAlignment(SwingConstants.LEADING);
                   setLayout(new GridLayout(1, 1));
                   removeAll();
                   add(text);
                   setBackground(text.getBackground());
                   if (table.getRowHeight() < getMinimumSize().height){
                        table.setRowHeight(getMinimumSize().height);
              return this;
         protected Color nextBackgroundColor(){
              backgroundColor = backgroundColor.equals(Color.WHITE) ? Color.PINK : Color.WHITE;
              return backgroundColor;
    }

  • Rotate position of JProgressBar component

    Dear All,
    I am new in javafx for animation. I am using JProgressBar component for describe the progress, but I want to rotate the bar to the vertical position thus the progress flow from bottom to up ( not left to right or it reverse). Any suggestion for me, please?
    endang

    JProgressBar? You can set the orientation in the constructor, no?
    Otherwise, with JavaFX 1.2, you can just use ProgressBar and rotate it:
    def BASE_SIZE = 400;
    var n: Number = 0;
    var progress: ProgressBar = ProgressBar
      progress: bind ProgressBar.computeProgress(100, n)
      transforms: Rotate { angle: -90 }
    n = 0;
    Stage
      title: "Native JavaFX Controls"
      scene: Scene
        width:  BASE_SIZE
        height: BASE_SIZE
        fill:   Color.web('#00BABE')
        content:
          Group
            translateX: 200
            translateY: 200
            content:
              progress
    var t = Timeline
      keyFrames:
        KeyFrame { time: 5s, values: n => 100 }
    t.play();

  • Define a range for JProgressBar

    Is it possible to define a range for JProgressBar object ??
    I want to paint a progress bar from say 30% to 70% with a color say "green".
    If i do:
    JProgressBar progressBar = new JProgressBar(ProgressBar.HORIZONTAL);
    progressBar.setForeground(Color.green);
    progressBar.setValue(30);
    // it paints till 30% of the progress Bar
    progressBar.setValue(70);
    // it will paint from start to 70% of the progress bar.
    Is it possible to extend JProgressBar classs and define our own MyProgressBar Class which does this task ??? I tried but was not able to succeed.
    any help would be appreciated
    regards,
    Kumar

    I'm not sure what the request is. Are you asking for a process bar where the entire bar changes color within a certain range (not too hard). Or a progress bar whose bar could be multiple colors at the same time?

  • JProgressBar is not updating even in new Thread !

    Hello every buddy....
    I'm new to SDN and I hope I'll enjoy being an active member.
    I've a problem with updating JProgressBar in actionPerformed method. I know that GUI can not be updating in the event dispatching thread, so, I created a new class to show the JProgress bar in a separate thread as follows:
    {color:#333399}import javax.swing.JProgressBar;
    import javax.swing.Frame;
    public class ProgressBar
    public ProgressBar()
    new Thread(new Runnable()
    public void run()
    showProgressBar();
    }).start();
    }// End of constructor
    private void showProgressBar()
    JProgressBar pb = new JProgressBar(0, 100);
    pb.setPainted(true);
    JFrame f = new Frame();
    f.setSize(250, 100);
    f.getContentPane().add(pb);
    f.setVisible(true);
    while( Crypt.done == false)
    pb.setValue( Crypt.percentageCompleted );
    f.dispose();
    f = null;
    }// End of showProgressBar method
    } // End of ProgressBar class
    {color}{color:#000000}I create an objmect of the above class inside another class called Crypt. when a button is clicked actionPerformed is invoked I do:
    ProgressBar progress = new ProgressBar();
    the frame f shows, but the JProgressBar never shows!
    Can anyone help me?
    with best wishes{color}

    scphan wrote:
    your declaration worked when i plugged it in into my program
    but the way you've programmed the JProgressBar to update is very inefficient, you should just get a ref to your JProgressBar and call setValue() from inside the loop of whatever you're doing
    Edited by: scphan on Mar 24, 2009 10:04 AMThat's bad advice. The setValue method must be invoked on the EDT. I suggest using a SwingWorker and its progress bound property:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html]

  • Can I show a color bar instead of a color bullet in iCal Monthly view for all my events in all calendars?

    In the Monthly view of iCal the only events that show a color bar in the event is the Birthday Calendar. All other events in all my other calendars only show a color bullet next to the event (unless I click on that event which then shows as a color bar). I would like to know if it is possible for all the calendar events to have a color bar in the monthly view instead of just that tiny color bullet.

    Greetings Judith,
    Before making any attempts at deleting calendar data, backup what you have just in case:
    Click on each calendar on the left hand side of iCal one at a time highlighting it's name and then going to File Export > Export and saving the resulting calendar file to a logical location for safekeeping.
    iCal has an automated function located in iCal > Preferences > Advanced > Delete events "X" days after they have passed.  By typing in a value for days you can tell iCal to delete all events before that time frame.
    Example:
    Today is 4-16-2012.
    If I wanted to delete all events prior to 1 year ago (4-16-2011) I would type in "365" for the number of days.
    Once you type in the number of days you want kept in iCal, close the preferences and then quit iCal.
    Re-open iCal and check to see if the events are gone.  If not you may want to leave it open for several minutes and then quit again.
    Once the events are removed go back to  iCal > Preferences > Advanced > Delete events "X" days after they have passed and make sure the check mark is removed to prevent future deletion.
    Hope that helps.

  • Fax function of HP LaserJet Enterprise 500 Color MFP M575

    Hi,
    I am one of users of HP LaserJet Enterprise 500 Color MFP M575​.
    I would like to know can I set the printer do not print my fax number and fax header on paper when I fax my document to others.
    I had login as admin but I did not see where I can config it.
    Thank you.
    Regards,
    Jimmy Pun

    There is no change to this problem after 6 months since the last post. Put simply, and as stated in the previous posts, there is no way to scan a document and receive the image on your PC. If you are working with graphics for any length of time or want to create an image for inclusion as an image in a document or web page using this piece of equipment will not allow you to do so.
    Great shame as every other function works well - it cannot be beyond the wit of HP to include a Windows application that enables you to scan an image, receive it in the software you are using at the time (e.g. Outlook, Word, Photoshop...) and use it in your work.
    HP Printers several years older than this £1000+ Enterprise printer were able to do this simple job and have done so for a great many years. Just being able to use Microsoft's Fax and Scan would be start.

  • HP LaserJet Enterprise 500 Color MFP M575 - Can't scan from Windows

    We recently purchased and installed an HP LaserJet Enterprise 500 Color MFP M575 to be used as a networked all-in-one solution for a number of offices. I have been able to get it set up on our network and have installed the appropriate drivers on the requested Windows 7 x64 machines, and network printing works perfectly. However, it seems that despite the fancy scanning features available from the all-in-one itself (scan to email, scan to a network folder, etc.), I can't find any way to do an old-fashioned scan from Windows.
    I have installed the full software solution available on the driver download page for the device, and while Windows lists the device as a "Multi Function Printer; Scanner" it does not recognize it as an actual scanner. The built-in Windows Fax and Scan simply reports that no scanners are installed. The software installation did not include the HP Solution Center (which I am used to seeing from my experience with various other HP all-in-one devices) or any equivalent for direct scanning. The driver download page for the device does not include any separate scanning drivers, so I can't be certain if they were included with the full installation or exist at all.Some of our staff also use Adobe Acrobat to scan, and even that fails to recognize the MFP as a scanner.
    We'll eventually be setting up the device to scan directly to a network folder, but we need a fallback while IT takes their time getting it set up; I can't imagine that the simplest option is not available at all. I must be missing something here, any assistance would be greatly appreciated.
    Edit: To add, I also ran the HP Print and Scan Doctor. Interestingly, it reports the device as a printer and only offers to "Fix Printing" without any sort of resolution for my scanning problem.

    There is no change to this problem after 6 months since the last post. Put simply, and as stated in the previous posts, there is no way to scan a document and receive the image on your PC. If you are working with graphics for any length of time or want to create an image for inclusion as an image in a document or web page using this piece of equipment will not allow you to do so.
    Great shame as every other function works well - it cannot be beyond the wit of HP to include a Windows application that enables you to scan an image, receive it in the software you are using at the time (e.g. Outlook, Word, Photoshop...) and use it in your work.
    HP Printers several years older than this £1000+ Enterprise printer were able to do this simple job and have done so for a great many years. Just being able to use Microsoft's Fax and Scan would be start.

Maybe you are looking for