Example usage for javax.swing JProgressBar JProgressBar

List of usage examples for javax.swing JProgressBar JProgressBar

Introduction

In this page you can find the example usage for javax.swing JProgressBar JProgressBar.

Prototype

public JProgressBar(BoundedRangeModel newModel) 

Source Link

Document

Creates a horizontal progress bar that uses the specified model to hold the progress bar's data.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Stepping Progress");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
    aJProgressBar.setStringPainted(true);
    aJProgressBar.setIndeterminate(true);

    frame.add(aJProgressBar, BorderLayout.NORTH);
    frame.setSize(300, 200);//  www  .jav  a  2  s. c  o m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JProgressBar bar = new JProgressBar(JProgressBar.VERTICAL);
    bar.setEnabled(true);/*from  w w  w . j a va 2 s  .  c om*/

    bar.setBackground(Color.YELLOW);
    bar.setForeground(Color.GREEN);

    bar.setStringPainted(true);
    bar.setString("2000 g");
    bar.setValue(65);
    frame.setLayout(new BorderLayout());
    frame.add(bar, BorderLayout.CENTER);
    frame.setSize(500, 400);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("ProgressBars");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JProgressBar dJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
    dJProgressBar.setValue(100);/*from  ww w .ja  va2s  .  c  o  m*/
    dJProgressBar.setBorderPainted(false);
    dJProgressBar.setString("Ack");
    dJProgressBar.setStringPainted(true);

    frame.add(dJProgressBar, BorderLayout.WEST);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:BoundedChangeListener.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Stepping Progress");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
    aJProgressBar.setStringPainted(true);

    aJProgressBar.addChangeListener(new BoundedChangeListener());

    for (int i = 0; i < 10; i++) {
        aJProgressBar.setValue(i++);/*from   ww  w. j av a  2  s .  c  o  m*/
        Thread.sleep(100);
    }

    frame.add(aJProgressBar, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    BoundedRangeModel model = new DefaultBoundedRangeModel();
    BlockedColorLayerUI layerUI = new BlockedColorLayerUI();
    JPanel p = new JPanel(new GridLayout(2, 1, 12, 12));

    p.add(new JLayer<JProgressBar>(new JProgressBar(model), layerUI));

    JPanel box = new JPanel();
    box.add(new JButton(new AbstractAction("+10") {
        private int i = 0;

        @Override//from  ww w.  ja  va  2  s. co m
        public void actionPerformed(ActionEvent e) {
            model.setValue(i = (i >= 100) ? 0 : i + 10);
        }
    }));

    p.repaint();

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(p, BorderLayout.NORTH);
    panel.add(box, BorderLayout.SOUTH);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(panel);
    f.setSize(320, 240);
    f.setVisible(true);
}

From source file:BarThread.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
    aJProgressBar.setStringPainted(true);

    JButton aJButton = new JButton("Start");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            aJButton.setEnabled(false);/*from  ww w . j  a  v a2  s.c o m*/
            Thread stepper = new BarThread(aJProgressBar);
            stepper.start();
        }
    };
    aJButton.addActionListener(actionListener);
    frame.add(aJProgressBar, BorderLayout.NORTH);
    frame.add(aJButton, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:BarThread.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Stepping Progress");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
    aJProgressBar.setStringPainted(true);

    final JButton aJButton = new JButton("Start");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            aJButton.setEnabled(false);//  w w  w.  j  av a 2s .  c o  m
            Thread stepper = new BarThread(aJProgressBar);
            stepper.start();
        }
    };
    aJButton.addActionListener(actionListener);
    frame.add(aJProgressBar, BorderLayout.NORTH);
    frame.add(aJButton, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

public JDialog showProgressDialog(JDialog progressParent, String title, String message,
        boolean includeCancelButton) {
    fileSearchCancelled = false;//  ww w  .  ja v  a 2s  .c o  m
    JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    cancel.addActionListener(event -> {
        fileSearchCancelled = true;
        ((JButton) event.getSource()).setEnabled(false);
    });
    final JDialog progressDialog = new JDialog(progressParent, title, false);
    bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    bar.setIndeterminate(true);
    if (includeCancelButton) {
        progressDialog.add(cancel, BorderLayout.SOUTH);
    }
    progressDialog.add(new JLabel(message), BorderLayout.NORTH);
    progressDialog.add(bar, BorderLayout.CENTER);
    progressDialog.pack();
    progressDialog.setLocationRelativeTo(null);
    progressDialog.setVisible(true);
    return progressDialog;
}

From source file:ch.fork.AdHocRailway.ui.AdHocRailway.java

private JPanel initStatusBar() {
    final JPanel statusBarPanel = new JPanel();
    commandHistoryModel = new DefaultComboBoxModel<String>();
    commandHistory = new JComboBox<String>(commandHistoryModel);
    commandHistory.setEditable(false);/*ww  w . j av a 2 s  .co m*/
    commandHistory.setFocusable(false);

    progressBar = new JProgressBar(SwingConstants.HORIZONTAL);

    statusBarPanel.setLayout(new BorderLayout(5, 0));
    statusBarPanel.add(progressBar, BorderLayout.WEST);
    statusBarPanel.add(commandHistory, BorderLayout.CENTER);
    return statusBarPanel;
}

From source file:de.bwravencl.controllerbuddy.gui.Main.java

private void initOverlay() {
    if (!preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, Toolkit.getDefaultToolkit().isAlwaysOnTopSupported()))
        return;//from w  ww .  j a v a  2s  .  c  o  m

    var longestDescription = "";
    for (final var mode : input.getProfile().getModes()) {
        final var description = mode.getDescription();
        if (description.length() > longestDescription.length())
            longestDescription = description;
    }

    final var fontMetrics = labelCurrentMode.getFontMetrics(labelCurrentMode.getFont());
    labelCurrentMode.setPreferredSize(
            new Dimension(fontMetrics.stringWidth(longestDescription), fontMetrics.getHeight()));
    labelCurrentMode.setForeground(Color.RED);
    labelCurrentMode.setText(input.getProfile().getActiveMode().getDescription());

    overlayFrame = new JFrame("Overlay");
    overlayFrame.setType(JFrame.Type.UTILITY);
    overlayFrame.setLayout(new BorderLayout());
    overlayFrame.setFocusableWindowState(false);
    overlayFrame.setUndecorated(true);
    overlayFrame.setBackground(TRANSPARENT);

    overlayFrame.add(labelCurrentMode, BorderLayout.PAGE_END);
    overlayFrame.setAlwaysOnTop(true);

    indicatorPanelFlowLayout = new FlowLayout();
    indicatorPanel = new JPanel(indicatorPanelFlowLayout);
    indicatorPanel.setBackground(TRANSPARENT);

    final var virtualAxisToOverlayAxisMap = input.getProfile().getVirtualAxisToOverlayAxisMap();
    for (final var virtualAxis : Input.VirtualAxis.values()) {
        final var overlayAxis = virtualAxisToOverlayAxisMap.get(virtualAxis);
        if (overlayAxis != null) {
            final var progressBar = new JProgressBar(SwingConstants.VERTICAL) {

                private static final long serialVersionUID = 8167193907929992395L;

                @Override
                public void setMaximum(final int n) {
                    if (overlayAxis.inverted)
                        super.setMinimum(-n);
                    else
                        super.setMaximum(n);
                }

                @Override
                public void setMinimum(final int n) {
                    if (overlayAxis.inverted)
                        super.setMaximum(-n);
                    else
                        super.setMinimum(n);
                }

                @Override
                public void setValue(final int n) {
                    super.setValue(overlayAxis.inverted ? -n : n);
                }
            };
            progressBar.setPreferredSize(new Dimension(21, 149));
            progressBar.setBorder(BorderFactory.createDashedBorder(Color.BLACK,
                    (float) progressBar.getPreferredSize().getWidth(),
                    (float) progressBar.getPreferredSize().getWidth()));
            progressBar.setBackground(Color.LIGHT_GRAY);
            progressBar.setForeground(overlayAxis.color);
            progressBar.setValue(1);
            indicatorPanel.add(progressBar);
            virtualAxisToProgressBarMap.put(virtualAxis, progressBar);
        }
    }

    overlayFrame.add(indicatorPanel);

    overlayFrameDragListener = new FrameDragListener(this, overlayFrame) {

        @Override
        public void mouseDragged(final MouseEvent e) {
            super.mouseDragged(e);
            final var maxWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getMaximumWindowBounds();
            updateOverlayAlignment(maxWindowBounds);
        }

    };
    overlayFrame.addMouseListener(overlayFrameDragListener);
    overlayFrame.addMouseMotionListener(overlayFrameDragListener);

    prevMaxWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    updateOverlayLocation(prevMaxWindowBounds);

    overlayFrame.setVisible(true);
}