List of usage examples for javax.swing JProgressBar JProgressBar
public JProgressBar(int min, int max)
From source file:Main.java
public Main() { super(new BorderLayout()); JProgressBar progressBar = new JProgressBar(0, 100); progressBar.setValue(0);//w w w . j a v a 2 s . co m progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setEditable(false); startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { startButton.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); final Task task = new Task(); task.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent pce) { if ("progress".equals(pce.getPropertyName())) { int progress = (Integer) pce.getNewValue(); progressBar.setValue(progress); taskOutput.append(String.format("Completed %d%% of task.\n", task.getProgress())); } } }); task.execute(); } }); JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); }
From source file:Main.java
public ProgressBarFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // this text area holds the activity output textArea = new JTextArea(); // set up panel with button and progress bar final int MAX = 1000; JPanel panel = new JPanel(); startButton = new JButton("Start"); progressBar = new JProgressBar(0, MAX); progressBar.setStringPainted(true);/* w w w . ja v a 2 s . com*/ panel.add(startButton); panel.add(progressBar); checkBox = new JCheckBox("indeterminate"); checkBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { progressBar.setIndeterminate(checkBox.isSelected()); progressBar.setStringPainted(!progressBar.isIndeterminate()); } }); panel.add(checkBox); add(new JScrollPane(textArea), BorderLayout.CENTER); add(panel, BorderLayout.SOUTH); // set up the button action startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { startButton.setEnabled(false); activity = new SimulatedActivity(MAX); activity.execute(); } }); }
From source file:ProgressBarTest.java
public ProgressBarFrame() { setTitle("ProgressBarTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // this text area holds the activity output textArea = new JTextArea(); // set up panel with button and progress bar final int MAX = 1000; JPanel panel = new JPanel(); startButton = new JButton("Start"); progressBar = new JProgressBar(0, MAX); progressBar.setStringPainted(true);//from w ww. ja v a 2 s . c o m panel.add(startButton); panel.add(progressBar); checkBox = new JCheckBox("indeterminate"); checkBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { progressBar.setIndeterminate(checkBox.isSelected()); progressBar.setStringPainted(!progressBar.isIndeterminate()); } }); panel.add(checkBox); add(new JScrollPane(textArea), BorderLayout.CENTER); add(panel, BorderLayout.SOUTH); // set up the button action startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { startButton.setEnabled(false); activity = new SimulatedActivity(MAX); activity.execute(); } }); }
From source file:ProgressBarDemo.java
public ProgressBarDemo() { super(new BorderLayout()); task = new LongTask(); //Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); progressBar = new JProgressBar(0, task.getLengthOfTask()); progressBar.setValue(0);/*from w ww . java 2 s.c om*/ progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false); taskOutput.setCursor(null); //inherit the panel's cursor //see bug 4851758 JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); //Create a timer. timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { progressBar.setValue(task.getCurrent()); String s = task.getMessage(); if (s != null) { taskOutput.append(s + newline); taskOutput.setCaretPosition(taskOutput.getDocument().getLength()); } if (task.isDone()) { Toolkit.getDefaultToolkit().beep(); timer.stop(); startButton.setEnabled(true); setCursor(null); //turn off the wait cursor progressBar.setValue(progressBar.getMinimum()); } } }); }
From source file:de.wusel.partyplayer.gui.LockingStatusbar.java
public LockingStatusbar(Application application, final JFrame mainFrame, final Settings settings) { this.application = application; this.settings = settings; this.application.getContext().getTaskMonitor().addPropertyChangeListener(listener); statusLabel = new JLabel("Ready"); fileReaderProgressBar = new JProgressBar(0, 100); pinCodeInputField = new JPasswordField(); PromptSupport.setPrompt("pin-code", pinCodeInputField); PromptSupport.setForeground(Color.GRAY, pinCodeInputField); pinCodeInputField.addMouseListener(new MouseAdapter() { @Override/* ww w .j av a2 s .c o m*/ public void mouseClicked(MouseEvent e) { if (!pinCodeInputField.isEnabled()) { ChangePasswordDialog dialog = new ChangePasswordDialog(mainFrame, settings); dialog.setVisible(true); if (dialog.getStatus() == DialogStatus.CONFIRMED) { settings.setNewPassword(dialog.getPassDigest()); settings.backup(PathUtil.getSettingsFile()); } } } }); pinCodeInputField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean unlocked = settings .isPasswordValid(DigestUtils.md5Hex(new String(pinCodeInputField.getPassword()))); if (unlocked) { pinCodeInputField.transferFocus(); unlock(); } pinCodeInputField.setText(null); } }); lockButton = new JToggleButton(); lockButton.setIcon(getIcon("lock")); lockButton.setSelectedIcon(getIcon("lock_open")); lockButton.setEnabled(false); lockButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { lock(); } }); this.settingsButton = new JButton(getIcon("cog_edit")); this.settingsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showSettings(); } }); add(statusLabel, new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL)); add(fileReaderProgressBar, new JXStatusBar.Constraint(200)); add(pinCodeInputField, new JXStatusBar.Constraint(100)); add(lockButton, new JXStatusBar.Constraint()); add(settingsButton, new JXStatusBar.Constraint()); this.mainFrame = mainFrame; }
From source file:components.ProgressBarDemo.java
public ProgressBarDemo() { super(new BorderLayout()); //Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); progressBar = new JProgressBar(0, 100); progressBar.setValue(0);// w w w. ja v a 2s . co m progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false); JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:components.ProgressBarDemo2.java
public ProgressBarDemo2() { super(new BorderLayout()); //Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); progressBar = new JProgressBar(0, 100); progressBar.setValue(0);/*from w ww . j ava 2 s. c o m*/ //Call setStringPainted now so that the progress bar height //stays the same whether or not the string is shown. progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false); JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:integratedprogressdemo.WeatherData.java
private WeatherData(boolean displayProgress) { setBackground(Color.WHITE);/* w w w.j a v a 2s . co m*/ setLayout(new BorderLayout()); JLabel lbl = new JLabel("World-Wide Weather Data"); lbl.setFont(new Font("Serif", Font.PLAIN, 18)); add(lbl, BorderLayout.PAGE_START); lbl = new JLabel("Weather information from over 50 cities"); add(lbl, BorderLayout.LINE_START); if (displayProgress) { progressPanel = new JPanel(); progressPanel.setBackground(Color.WHITE); progressPanel.setLayout(new BorderLayout(20, 20)); String lblText = "<html>Stuck in the mud? Make progress with...<br /><font color=red><em>JDK Documentation</em></font><br/></html>"; lbl = new JLabel(lblText); progressPanel.add(lbl, BorderLayout.NORTH); progressBar = new JProgressBar(0, 100); progressBar.setValue(0); progressBar.setStringPainted(true); progressPanel.add(progressBar, BorderLayout.SOUTH); add(progressPanel, BorderLayout.LINE_END); } String[] columnNames = { "City", "Temperature" }; JTable table = new JTable(getData(), columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); scrollPane.setBackground(Color.WHITE); //Add the scroll pane to this panel. add(scrollPane, BorderLayout.PAGE_END); }
From source file:ProgressBarDemo.java
public ProgressBarDemo() { super(new BorderLayout()); // Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); progressBar = new JProgressBar(0, 100); progressBar.setValue(0);/*from w w w. j a v a 2s . c o m*/ progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false); JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:Main.java
public Main() { super(new BorderLayout()); // Create the demo's UI. startButton = new JButton("Start"); startButton.setActionCommand("start"); startButton.addActionListener(this); progressBar = new JProgressBar(0, 100); progressBar.setValue(0);/*from ww w . j a va2s . co m*/ // Call setStringPainted now so that the progress bar height // stays the same whether or not the string is shown. progressBar.setStringPainted(true); taskOutput = new JTextArea(5, 20); taskOutput.setMargin(new Insets(5, 5, 5, 5)); taskOutput.setEditable(false); JPanel panel = new JPanel(); panel.add(startButton); panel.add(progressBar); add(panel, BorderLayout.PAGE_START); add(new JScrollPane(taskOutput), BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }