Changes in JProgressBar

hi,
who can show me a simple example of a jprogressbar.
please use a loop with 1000 steps.
i had try it but the progress won't be displayed.
thanks

here, look at this tutorial for using progress bar:
http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html

Similar Messages

  • [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

  • Set the JProgressBar size

    Hi all,
    I've added a JProgressBar in to a JFrame as follows.
            progBar = new JProgressBar(0, 100);
            progBar.setValue(0);
            progBar.setBorderPainted(true);It's working fine. But I'm stuck on one thing. I cannot change the length of the JProgressBar. It's use a same length even I've change the length(width) of the JFrame. How can I change that.
    I've read the doc, but didn't found the way to change it's size. Please help me.

    ItsJava wrote:
    So JProgressBar is a swing component and the JProgressClass inherit Component class. So all the methods in Component class methods are valid here. Am I right?Yes, you are right. The preferredSize, however, will only be honored if you're using a layout manager (which shows you are). And even with layout managers, it's only the "preferred" size, so it may not always be honored given the circumstances.

  • How refresh JProgressBar display ?

    I use a JProgressBar in my program but the display of it is never refresh even if I use updateUI method.
    Do you know a way to have a real refresh of my display ?

    you need to implement a model and associate it to the GUI:
    take a look in the BoundedRangeModel class....
    http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
    the code bellow is a large one I used in a class about Model-View-Controller paradigm.. It is big, but I hope it help you...
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.event.*;
    * This test class demonstrates the control-model-view programing paradigm
    * @version 1.0 beta
    * @author Felipe Gaucho
    * @date september 2000
    public class CMV
         Model model = null;
         static public void main(String[] args)
              try
                   new CMV(Integer.parseInt(args[0]));
              catch(Exception error)
                   new CMV(1000); // Default test value
         CMV(int limit)
              // Creates a data model
              model = new Model(limit);
              // Set the model observers
              model.addObserver(new SwingView(model));
              model.addObserver(new AwtView());
              // Set a controller to the model
              Control controller = new Control(model);
    // VIEW
    class SwingView extends JFrame implements Observer
         JProgressBar progress = null;
         JSlider slider = null;
         SwingView(Model model)
              super("Swing Viewer");
              try
                   //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                   //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
                   //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch(Exception error)
              // Creates a new progress bar indicating the model status
              progress = new JProgressBar(model);
              progress.setStringPainted(true);
              // Creates a new slider providing an interactive way of model data modifying
              slider = new JSlider(model);
              slider.setVisible(false);
              // Swing layout mounting
              getContentPane().setLayout(new BorderLayout(2,2));
              getContentPane().add(new JLabel("Swing do it better!", JLabel.CENTER), BorderLayout.CENTER);
              getContentPane().add(progress, BorderLayout.SOUTH);
              getContentPane().add(slider, BorderLayout.NORTH);
              setSize(250,100);
              setLocation(50,50);
              setVisible(true);
         public void update(Observable model, Object component)
              if( ! slider.isVisible() && ((Model)model).getValue() == ((Model)model).getMaximum())
                   slider.setVisible(true);
              progress.repaint();
    // VIEW
    class AwtView extends Frame implements Observer
         Label valueInfo = new Label("", Label.CENTER);
         AwtView()
              // Set title and layout type
              super("Awt Viewer");
              setLayout(new BorderLayout());
              // Set the layout components
              add(new Label("Awt use light weight components!", Label.CENTER), BorderLayout.CENTER);
              valueInfo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,32));
              add(valueInfo, BorderLayout.SOUTH);
              // Display it
              setSize(250,100);
              setLocation(350,50);
              setVisible(true);
         public void update(Observable model, Object component)
              valueInfo.setText(((Model)model).getValue() + " / " + ((Model)model).getMaximum());
    // MODEL
    class Model extends Observable implements BoundedRangeModel
         private int value = 0;
         private int minimum = 0;
         private int maximum = 0;
         Model(int maximum)
              this(0, maximum, 0);
         Model(int minimum, int maximum, int initialValue)
              this.minimum = minimum;
              this.maximum = maximum;
              this.value = initialValue;
         public void addChangeListener(ChangeListener x) {}
         public int getExtent() {return 1;}
         public int getMaximum() {return maximum;}
         public int getMinimum() {return minimum;}
         public int getValue() {return value;}
         public boolean getValueIsAdjusting (){return true;}
         public void removeChangeListener(ChangeListener x){}
         public void setExtent(int newExtent) {}
         public void setMaximum(int newMaximum) {}
         public void setMinimum(int newMinimum) {}
         public void setRangeProperties(int value, int extent, int min, int max, boolean adjusting) {}
         public void setValue(int value)
              this.value = value;
              setChanged();
              notifyObservers();  // <== Notify the observers about the model data changing
         public void setValueIsAdjusting(boolean b) {}
    // CONTROL
    class Control
         private Model model = null;
         Control(Model model)
              this.model = model;
              int limit = model.getMaximum();
              for(int i=0; i<limit; i++)
                   model.setValue((model.getValue())+1);
    }

  • JProgressBar in JTable overwrites cell bounds

    Problem: When the user resizes the table (during a update) so that the entire JProgressBar will no longer fit in the cell, the text of the JProgressBar will overwrite its surrounding controls.
    Sample code:
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    public class Main extends JFrame {
    public Main() {
    super("TableModel JProgressBar Demonstration");
    // create our own custom TableModel
    DownloadTableModel downloadModel = new DownloadTableModel();
    JTable table = new JTable(downloadModel);
    // add rows to our TableModel, each row is represented as a Download object
    downloadModel.addDownload(new Download("linuxmandrake.zip", 1234567));
    downloadModel.addDownload(new Download("flash5.exe", 56450000));
    downloadModel.addDownload(new Download("jdk1.2.2-007.zip", 20000000));
    // render the columns with class JProgressBar as such
    ProgressBarRenderer pbr = new ProgressBarRenderer(0, 100);
    pbr.setStringPainted(true);
    table.setDefaultRenderer(JProgressBar.class, pbr);
    // increase the height of the rows a bit
    table.setRowHeight((int) pbr.getPreferredSize().getHeight());
    // create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    // add the scroll pane to this window.
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    getContentPane().add(new JButton("Spacer"), BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    public static void main(String[] args) {
    Main main = new Main();
    main.pack();
    main.setVisible(true);
    // a simple object that holds data about a particular download
    // it starts a thread and increases the progress of "downloading"
    // in a random manner
    class Download extends Observable implements Runnable {
    private Thread thisThread;
    private String filename;
    private int filesize;
    private float progress;
    public Download(String filename, int filesize) {
    this.filename = filename;
    this.filesize = filesize;
    progress = 0.0f;
    thisThread = new Thread(this);
    thisThread.start();
    public String getFilename() { return filename; }
    public int getFilesize() { return filesize; }
    public float getProgress() { return progress; }
    public String toString() {
    return "[" + filename + ", " + filesize + ", " + progress + "]"; }
    public void run() {
    Random r = new Random();
    int count = 0;
    while (count < filesize) {
    int random = Math.abs(r.nextInt() % 100000);
    count += random;
    if (count > filesize) count = filesize;
    progress = ((float) count / filesize) * 100;
    // notify table model (and all other observers)
    setChanged();
    notifyObservers(this);
    try { thisThread.sleep(500); } catch(InterruptedException e) { }
    class DownloadTableModel extends AbstractTableModel implements Observer {
    // holds the strings to be displayed in the column headers of our table
    final String[] columnNames = {"Filename", "Filesize", "Progress"};
    // holds the data types for all our columns
    final Class[] columnClasses = {String.class, Integer.class, JProgressBar.class};
    // holds our data
    final Vector data = new Vector();
    // adds a row
    public void addDownload(Download d) {
    data.addElement(d);
    // the table model is interested in changes of the rows
    d.addObserver(this);
    fireTableRowsInserted(data.size()-1, data.size()-1);
    // is called by a download object when its state changes
    public void update(Observable observable, Object o) {
    int index = data.indexOf(o);
    if (index != -1)
    fireTableRowsUpdated(index, index);
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.size();
    public String getColumnName(int col) {
    return columnNames[col];
    public Class getColumnClass(int c) {
    return columnClasses[c];
    public Object getValueAt(int row, int col) {
    Download download = (Download) data.elementAt(row);
    if (col == 0) return download.getFilename();
    else if (col == 1) return new Integer(download.getFilesize());
    else if (col == 2) return new Float(download.getProgress());
    else return null;
    public boolean isCellEditable(int row, int col) {
    return false;
    // a table cell renderer that displays a JProgressBar
    class ProgressBarRenderer extends JProgressBar implements TableCellRenderer {
    public ProgressBarRenderer() {
    super();
    public ProgressBarRenderer(BoundedRangeModel newModel) {
    super(newModel);
    public ProgressBarRenderer(int orient) {
    super(orient);
    public ProgressBarRenderer(int min, int max) {
    super(min, max);
    public ProgressBarRenderer(int orient, int min, int max) {
    super(orient, min, max);
    public Component getTableCellRendererComponent(
    JTable table, Object value, boolean isSelected, boolean hasFocus,
    int row, int column) {
    setValue((int) ((Float) value).floatValue());
    return this;
    }

    I do not have an answer for you.
    However, I did skim through a solution to your problem. Since it didn't solve my problem at the time, I didn't try out the code.
    In the book "Core Web Programming", Second Edition, Marty Hall and Larry Brown, Sun Microsystems Press, they do discuss making a progress bar synchronize with a file download and why you have to make it multi-threaded.
    If you can head over to your bookstore, it's Chapter 15.6 and consists of about two and a half pages. Even better, the example's source code is available for free on their web site at:
    http://www.corewebprogramming.com
    Click on the hypertext link to Chapter 15, then scroll down and grab FileTransfer.java near the bottom of the page.
    Hope this at least points you in the right direction, but I admit I wouldn't even allow the user to resize the table containing the progress bar to begin with. If I absolutely had to, I'd force the progress bar thread to reset itself each time it received a window-resizing event.

  • 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);
    }

  • JProgressBar and file transfer

    Hi, I am trying to use a JProgressBar to determine how many bytes have been sent so far. I have constructed the JProgressBar with the maximum size of the file size. For each 'segment' of the file sent, the progress bar should increment using the setProgress() within the SwingWorker class. If I print the values out, they appear to be correct. However, if I use setProgress() the file transfer seems to fail (not even begin).
    Here's the relevant code:
    public class FileTracker extends JDialog implements PropertyChangeListener {
         private JPanel mainPnl = new JPanel(new BorderLayout());
         private JPanel progressBarPnl = new JPanel(new BorderLayout());
         private JPanel midPnl = new JPanel(new GridBagLayout());
         private JPanel bottomPnl = new JPanel(new GridBagLayout());
         private JLabel fileNameLbl = new JLabel("File name: ");
         private JLabel fileNamexLbl = new JLabel();
         private JLabel sizeLbl = new JLabel("File size: ");
         private JLabel sizexLbl = new JLabel();
         private JButton cancelBtn = new JButton("Cancel");
         private JProgressBar progressBar;
         private FileSender fileSender;
         private FileReceiver fileReceiver;
         private File file;
         public FileTracker(JFrame parent, String ip, int port, File file) {
              super (parent);
              this.file = file;
              fileSender = new FileSender(ip, port, file);
              fileSender.addPropertyChangeListener(this);
              fileSender.execute();
              setLocationRelativeTo(null);
              progressBar = new JProgressBar();
              progressBar.setMaximum((int)file.length());
              add(progressBarPanel());
              setResizable(false);
              setTitle("File sending..");
              pack();
              setVisible(true);
         private JPanel progressBarPanel() {
              progressBar.setValue(0);
              progressBar.setEnabled(true);
              progressBar.setStringPainted(true);
              progressBar.setIndeterminate(true);
              progressBarPnl.add(progressBar, BorderLayout.CENTER);
              return progressBarPnl;
         public void propertyChange(PropertyChangeEvent evt) {
            if ("progress" == evt.getPropertyName()) {
                int progress = (Integer) evt.getNewValue();
                if (progressBar.isIndeterminate())
                     progressBar.setIndeterminate(false);
                progressBar.setValue(progress);
                if (fileSender != null && fileSender.isDone())
                     progressBar.setString("Transfer finished");
                if (fileReceiver != null && fileReceiver.isDone())
                     progressBar.setString("Transfer finished");
    }The SwingWorker:
    public class FileSender extends SwingWorker<Void, Void> {
         private Socket socket;
         private FileInputStream fileIn;
         private OutputStream output;
         private File file;
         private byte buffer[];
         private int bufferSize;
         int bytesRead;
         int progress = 0;
         public FileSender(String ipAddress, int port, File file) {
              try {
                   System.out.printf("NOTICE: FileSender initialised. Sending to:%s on port: %d\n", ipAddress, port);
                   socket = new Socket(InetAddress.getByName(ipAddress), port);
                   output = socket.getOutputStream();
                   bufferSize = socket.getSendBufferSize();
                   buffer = new byte[bufferSize];
                   this.file = file;
                   setProgress(0);
              } catch (UnknownHostException e) {
                   // THE USER MUST BE INFORMED THAT THE RECIPIENT COULD NOT BE RESOLVED
                   e.printStackTrace();
              } catch (java.net.ConnectException ce) {
                   // INFORM THE USER THAT THE RECIPIENT COULD NOT BE REACHED
                   ce.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public Void doInBackground() {
                   sendFile();
              return null;
         public void sendFile() {
              System.out.printf("NOTICE: Sending file %s   %d bytes formed of %d segments.\n", file.getName(), file.length(), file.length()/bufferSize < 1 ? 1 : file.length()/bufferSize);
              try {
                   fileIn = new FileInputStream(file);
                   while ((bytesRead = fileIn.read(buffer)) > 0) {
                        output.write(buffer, 0 , bytesRead);
                        progress = progress + bufferSize;
                        if (progress  < file.length())
                             setProgress(progress);
                        else
                             setProgress((int)file.length());
                   output.close();
                   fileIn.close();
                   socket.close();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException ioe) {
                   ioe.printStackTrace();
    }This has been bugging me for a long time. Any help/suggestions much appreciated.

    when you create an SSCCE and get rid of all the File, socket, streams and whatnot (something that you should do next time), you notice something funny:
    import java.awt.BorderLayout;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.SwingWorker;
    public class FileTracker extends JDialog implements PropertyChangeListener
        private static final int MAX = 500;
        private JPanel progressBarPnl = new JPanel(new BorderLayout());
        private JProgressBar progressBar;
        private FileSender fileSender;
        private FileReceiver fileReceiver;
        public FileTracker(JFrame parent)
            super(parent);
            fileSender = new FileSender(MAX);
            fileSender.addPropertyChangeListener(this);
            fileSender.execute();
            setLocationRelativeTo(null);
            progressBar = new JProgressBar();
            progressBar.setMaximum(MAX);
            add(progressBarPanel());
            setResizable(false);
            setTitle("File sending..");
            pack();
            //setVisible(true);
        private JPanel progressBarPanel()
            progressBar.setValue(0);
            progressBar.setEnabled(true);
            progressBar.setStringPainted(true);
            progressBar.setIndeterminate(true);
            progressBarPnl.add(progressBar, BorderLayout.CENTER);
            return progressBarPnl;
        public void propertyChange(PropertyChangeEvent evt)
            //if ("progress" == evt.getPropertyName()) // *** avoid doing this
            if ("progress".equals(evt.getPropertyName()))
                int progress = (Integer) evt.getNewValue();
                progressBar.setValue(progress);
                System.out.println("progress is: " + progress);
                if (fileSender != null && fileSender.isDone())
                    progressBar.setString("Transfer finished");
                    System.out.println("file sender is done");
                if (fileReceiver != null && fileReceiver.isDone())
                    progressBar.setString("Transfer finished");
                    System.out.println("file receiver is done");
        private class FileReceiver
            public boolean isDone()
                return false;
        private class FileSender extends SwingWorker<Void, Void>
            private int max;
            private int bufferSize;
            int bytesRead;
            int progress = 0;
            public FileSender(int max)
                this.max = max;
                System.out.println("NOTICE: FileSender initialised. ");
                bufferSize = max;
                setProgress(0);
            public Void doInBackground()
                sendFile();
                return null;
            public void sendFile()
                System.out.println("NOTICE: Sending file ");
                System.out.println("Max = " + max);
                bufferSize = 10;
                while (progress < max)
                    try
                        Thread.sleep(100);
                    catch (InterruptedException e)
                        e.printStackTrace();
                    progress += bufferSize;
                    if (progress < max)
                        setProgress(progress);
                    else
                        setProgress(max);
                System.out.println("after while loop");
        private static void createAndShowUI()
            JFrame frame = new JFrame("FileTracker");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            FileTracker filetracker = new FileTracker(frame);
            filetracker.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }The SwingWorker stops when only 20% of "file transfer" has occurred, but when the progress has reached 100. Then if you go into the [SwingWorker API for setProgress|http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html#setProgress(int)] , you see why the program is stopping here: the SwingWorker stops when its progress property reaches 100. So you must change this to a ratio rather than total bytes.

  • JProgressBar look and feel

    Hi,
    I have a JProgressBar running in indeterminate mode in my application, however I don't really like the look of it (it kinda looks like a paddle moving back and forth like in one of those games).
    Anyway is there some way of changing the style or look of it? Is there sub-classes from JProgressBar that are different?
    cheers
    Oliver

    Take a look here:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/plaf/basic/BasicProgressBarUI.html
    Get the source from src.zip and play with modifying your own version of this one should do it.

  • 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;
    }

  • Changing labels in jtree

    i have tree with two kinds of nodes. groups and items. when user clicks on group all items and sub-groups are loaded from database via network in treeWillExpand method. this may take few seconds. when data is loadanig i would like to change label on group for example to "data is loading...". and after data is loaded and node expanded i would like to go back to previous label on group. any idesas ?

    Start a separate to execute the database query, so you don't lock the GUI from repainting. Then Change the data in the node. When Database query finishes upate the node and make sure to use the SwingUtilities.invokeLater(...) method.
    Read this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html]How to Use Threads for more information
    Or you can always use a JProgressBar for this purpose. The tutorial also has an example of this.

  • 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.

  • 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?

  • Swing Gurus Help! Problem updating a JProgressBar from within a listener.

    Hello all,
    I have a static JProgressBar attached to the Main JFrame of my application. One of the screens of my app has a JTable on it. I have a ListSelectionListener attached to the table. When an item is selected on the JTable, I pull some information out of it (Using the ListSelectionModel) and kick off a pretty lengthy process. This of course all happens inside the ListSelectionListener. My problem is that when I call into my JFrame (MainFrame.java) to update the ProgressBar, nothing happens.
    The first line of my valueChanged(ListSelecteEvent e) method is
    if (e.getValueIsAdjusting()) return; The next line is call to the progress bar:
    MainFrame.setExecutionProgress(10, "Opening...");When the code is like this, the progress bar isn't updated until after the method valueChanged() method returns. However, if I put the call to setExecutionProgress() before the if (e.getValueIsAdjusting()) check, the progress bar actually changes.
    The second scenario I mentioned above doesn't really help me because subsequent calls to MainFrame.setExecutionProgress() don't work from within the body of the valueChanged() method until it has returned.
    Is this a threading issue? I've tried wrapping calls with SwingUtilitilies.invokeLater(), but I can't get anythin to work. Any ideas?
    Thanks much in advance.
    -Toby

    Where do you kick off this 'lengthy process'? The process is kicked off within the listener. What makes it long is that some of the objects created in this process have to reach out to a web-service for initialization.
    Also, how do you know how far the lengthy process is?Well I create a few projects and just bump the progress meter by 10 or so with each object. I'm not really worried about the accuracy of the progress meter (a la Microsoft =), because I just want to give the user some visual indication something is happening behind the scenes (besides the hour-glass).
    I think I understand how you'd kick this process off in a thread, but how would you create another thread that's capable of monitoring the first? I mean how do you accomplish the inter-thread communication?
    ddinks much for the help!
    -Toby

  • Need help getting jprogressbar to work

    Currently, the JProgressBar will not change until the progress is finished. When the progress finishes, it will go to 100%
    public JProgressBar jjj;
            try {
                //thebar.setValue(0);
                jjj.setValue(0);
                URL strona = new URL(url2);
                URLConnection conn = strona.openConnection();
                filelength = Integer.parseInt(conn.getHeaderField("content-length"), 10);
                total = 0;
                out = new FileOutputStream("c:/youtubeconverter/videos/" + file + ".mp4");
                InputStream instream = conn.getInputStream();
                byte[] tmpbufor = new byte[128 * 1024];
                while ((wbuforze = instream.read(tmpbufor)) > 0)
                    out.write(tmpbufor, 0, wbuforze);
                    total += wbuforze;
                    jjj.setValue((int) ((100 * total) / filelength));
                    while (ispaused && !isstopped) {
                        try
                            this.sleep(100);
                        catch (InterruptedException ex) {
                    if (isstopped) {
                        break;
                }

    (groan) Never call sleep on the EDT. Read this:
    The Java&#8482; Tutorials: [Concurrency in Swing|http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html]
    While there, find and read the tutorial on how to use progress bars.
    db

  • All components not updating when I change the L&F

    I have developed a GUI and want Windows LookAndFeel for it. Please excuse me if I use some terms incorrectly. I'll explain my class structure first -
    1. class MainWindow - Contains the main method and invokes MainFrame
    2. class MainFrame - Creates the basic GUI and all the components and their event-handlers
    3.class MainPanel - Contains the actions to be taken in response to an event in MainFrame
    4. Dialog Boxes : Their are several classes implementing several dialog boxes which I load as needed.
    I have changed the L&F in the MainFrame class after all the MainFrame class components have been loaded. I have also used updateComponentTreeUI( ) to update all components already formed. I found out that not all components are having the Windows L&F when I tried out a JProgressBar. Instead of the green-broken progress indicator (Windows XP style), it was showing the gray-filled indicator (Java style). Then I noticed even the Menu Items are having the default L&F. Can anyone comment. Not giving any code because I am not sure which part of the huge GUI code should I post, i.e. where the problem really lies.

    You just said it doesn't work for a menu. So you
    create a frame with a menu and a menu item. About 10
    lines of code. Then you add two buttons one to switch
    to the Windows LAF the other to the Metal LAF.
    Another 10 lines of code. Now you have your demo
    program.No no, you din't get me. I know the basics regarding L&F. All the components are working fine, but that JProgressBar is not showing the XP view. Forget the JMenuItems, I am not sure the view is Windows L&F or Metal L&F, but I am sure the JProgressBar is not Windows L&F (while the rest of the components in the dialog box are perfect). Could this be due to something that I missed out while implementing the JProgressBar. But the Windows L&F is loaded before the dialog box containing the progress bar comes in. Your answer to my last Swing post helped me a lot. Hope you (or anyone else) can help me with this too

Maybe you are looking for