/** * Paints the progress string. * * @param g Graphics used for drawing. * @param x x location of bounding box * @param y y location of bounding box * @param width width of bounding box * @param height height of bounding box * @param fillStart start location, in x or y depending on orientation, of the filled portion of * the progress bar. * @param amountFull size of the fill region, either width or height depending upon orientation. * @param b Insets of the progress bar. */ private void paintString( Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2 = (Graphics2D) g; String progressString = progressBar.getString(); g2.setFont(progressBar.getFont()); Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height); Rectangle oldClip = g2.getClipBounds(); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { g2.setColor(getSelectionBackground()); SwingUtilities2.drawString( progressBar, g2, progressString, renderLocation.x, renderLocation.y); g2.setColor(getSelectionForeground()); g2.clipRect(fillStart, y, amountFull, height); SwingUtilities2.drawString( progressBar, g2, progressString, renderLocation.x, renderLocation.y); } else { // VERTICAL g2.setColor(getSelectionBackground()); AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); g2.setFont(progressBar.getFont().deriveFont(rotate)); renderLocation = getStringPlacement(g2, progressString, x, y, width, height); SwingUtilities2.drawString( progressBar, g2, progressString, renderLocation.x, renderLocation.y); g2.setColor(getSelectionForeground()); g2.clipRect(x, fillStart, width, amountFull); SwingUtilities2.drawString( progressBar, g2, progressString, renderLocation.x, renderLocation.y); } g2.setClip(oldClip); }
public JDialog showProgressDialog( JDialog parent, String title, String message, boolean includeCancelButton) { fileSearchCancelled = false; final JDialog prog; JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL); JButton cancel = new JButton(Globals.lang("Cancel")); cancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { fileSearchCancelled = true; ((JButton) event.getSource()).setEnabled(false); } }); prog = new JDialog(parent, title, false); bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); bar.setIndeterminate(true); if (includeCancelButton) { prog.add(cancel, BorderLayout.SOUTH); } prog.add(new JLabel(message), BorderLayout.NORTH); prog.add(bar, BorderLayout.CENTER); prog.pack(); prog.setLocationRelativeTo(null); // parent); // SwingUtilities.invokeLater(new Runnable() { // public void run() { prog.setVisible(true); // } // }); return prog; }
private void initComponents() { jfxPanel = new JFXPanel(); createScene(); ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadURL(txtURL.getText()); } }; btnGo.addActionListener(al); txtURL.addActionListener(al); progressBar.setPreferredSize(new Dimension(150, 18)); progressBar.setStringPainted(true); JPanel topBar = new JPanel(new BorderLayout(5, 0)); topBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); topBar.add(txtURL, BorderLayout.CENTER); topBar.add(btnGo, BorderLayout.EAST); JPanel statusBar = new JPanel(new BorderLayout(5, 0)); statusBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); statusBar.add(lblStatus, BorderLayout.CENTER); statusBar.add(progressBar, BorderLayout.EAST); panel.add(topBar, BorderLayout.NORTH); panel.add(jfxPanel, BorderLayout.CENTER); panel.add(statusBar, BorderLayout.SOUTH); frame.getContentPane().add(panel); }
/** * And now for a little assembly. Put together the buttons, progress bar and status text field. */ Example1(String name) { setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), name)); progressBar.setMaximum(NUMLOOPS); startButton = new JButton("Start"); startButton.addActionListener(startListener); startButton.setEnabled(true); interruptButton = new JButton("Cancel"); interruptButton.addActionListener(interruptListener); interruptButton.setEnabled(false); JComponent buttonBox = new JPanel(); buttonBox.add(startButton); buttonBox.add(interruptButton); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(buttonBox); add(progressBar); add(statusField); statusField.setAlignmentX(CENTER_ALIGNMENT); buttonBox.setBorder(spaceBelow); Border pbBorder = progressBar.getBorder(); progressBar.setBorder(BorderFactory.createCompoundBorder(spaceBelow, pbBorder)); }
/** * Returns an enum indicating how the baseline of the component changes as the size changes. * * @throws NullPointerException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) { super.getBaselineResizeBehavior(c); if (progressBar.isStringPainted() && progressBar.getOrientation() == JProgressBar.HORIZONTAL) { return Component.BaselineResizeBehavior.CENTER_OFFSET; } return Component.BaselineResizeBehavior.OTHER; }
/** * Sets the index of the current animation frame to the specified value and requests that the * progress bar be repainted. Subclasses that don't use the default painting code might need to * override this method to change the way that the <code>repaint</code> method is invoked. * * @param newValue the new animation index; no checking is performed on its value * @see #incrementAnimationIndex * @since 1.4 */ protected void setAnimationIndex(int newValue) { if (animationIndex != newValue) { if (sizeChanged()) { animationIndex = newValue; maxPosition = 0; // needs to be recalculated delta = 0.0; // needs to be recalculated progressBar.repaint(); return; } // Get the previous box drawn. nextPaintRect = getBox(nextPaintRect); // Update the frame number. animationIndex = newValue; // Get the next box to draw. if (nextPaintRect != null) { boxRect = getBox(boxRect); if (boxRect != null) { nextPaintRect.add(boxRect); } } } else { // animationIndex == newValue return; } if (nextPaintRect != null) { progressBar.repaint(nextPaintRect); } else { progressBar.repaint(); } }
protected void installListeners() { // Listen for changes in the progress bar's data. changeListener = getHandler(); progressBar.addChangeListener(changeListener); // Listen for changes between determinate and indeterminate state. progressBar.addPropertyChangeListener(getHandler()); }
private void startAction(boolean export) { optionsFrame.setVisible(false); progressBar.setValue(0); progressBar.setIndeterminate(true); textArea.setText(""); progressFrame.setVisible(true); new Thread(new ImportExportRunnable(export)).start(); }
@Override public void propertyChange(PropertyChangeEvent evt) { String strPropertyName = evt.getPropertyName(); if ("progress".equals(strPropertyName)) { progressBar.setIndeterminate(false); int progress = (Integer) evt.getNewValue(); progressBar.setValue(progress); } }
private void rebuildPassesMap(@NotNull DaemonCodeAnalyzerStatus status) { passes.clear(); for (ProgressableTextEditorHighlightingPass pass : status.passStati) { JProgressBar progressBar = new JProgressBar(0, MAX); progressBar.setMaximum(MAX); progressBar.putClientProperty("JComponent.sizeVariant", "mini"); JLabel percLabel = new JLabel(); percLabel.setText(TrafficProgressPanel.MAX_TEXT); passes.put(pass, Pair.create(progressBar, percLabel)); } }
/** * Returns the baseline. * * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public int getBaseline(JComponent c, int width, int height) { super.getBaseline(c, width, height); if (progressBar.isStringPainted() && progressBar.getOrientation() == JProgressBar.HORIZONTAL) { FontMetrics metrics = progressBar.getFontMetrics(progressBar.getFont()); Insets insets = progressBar.getInsets(); int y = insets.top; height = height - insets.top - insets.bottom; return y + (height + metrics.getAscent() - metrics.getLeading() - metrics.getDescent()) / 2; } return -1; }
public void status_Proses(boolean sukses, String status, int nilaiProsesBar) { statusProses.setText(status); prosesBar.setValue(prosesBar.getValue() + nilaiProsesBar); if (proses == false) { JOptionPane.showMessageDialog(null, "Gagal Login\nKarena" + statusGagal); removeAll(); dispose(); new LoginDialog_Database().show(); } proses = sukses; statusGagal = status; }
private void createProgressBarsInFrame( JFrame frame, JProgressBar progressBar1, JProgressBar progressBar2) { progressBar1.setValue(progressBar1.getMaximum()); frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS)); frame.getContentPane().add(progressBar1); JPanel panel = new JPanel(); frame.getContentPane().add(panel); panel.add(progressBar2); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
@Override @SuppressWarnings("SleepWhileHoldingLock") public void run() { try { // initialize the statusbar status.removeAll(); JProgressBar progress = new JProgressBar(); progress.setMinimum(0); progress.setMaximum(doc.getLength()); status.add(progress); status.revalidate(); // start writing Writer out = new FileWriter(f); Segment text = new Segment(); text.setPartialReturn(true); int charsLeft = doc.getLength(); int offset = 0; while (charsLeft > 0) { doc.getText(offset, Math.min(4096, charsLeft), text); out.write(text.array, text.offset, text.count); charsLeft -= text.count; offset += text.count; progress.setValue(offset); try { Thread.sleep(10); } catch (InterruptedException e) { Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e); } } out.flush(); out.close(); } catch (IOException e) { final String msg = e.getMessage(); SwingUtilities.invokeLater( new Runnable() { public void run() { JOptionPane.showMessageDialog( getFrame(), "Could not save file: " + msg, "Error saving file", JOptionPane.ERROR_MESSAGE); } }); } catch (BadLocationException e) { System.err.println(e.getMessage()); } // we are done... get rid of progressbar status.removeAll(); status.revalidate(); }
@Override public void run() { try { // initialize the statusbar status.removeAll(); JProgressBar progress = new JProgressBar(); progress.setMinimum(0); progress.setMaximum((int) f.length()); status.add(progress); status.revalidate(); // try to start reading Reader in = new FileReader(f); char[] buff = new char[4096]; int nch; while ((nch = in.read(buff, 0, buff.length)) != -1) { doc.insertString(doc.getLength(), new String(buff, 0, nch), null); progress.setValue(progress.getValue() + nch); } } catch (IOException e) { final String msg = e.getMessage(); SwingUtilities.invokeLater( new Runnable() { public void run() { JOptionPane.showMessageDialog( getFrame(), "Could not open file: " + msg, "Error opening file", JOptionPane.ERROR_MESSAGE); } }); } catch (BadLocationException e) { System.err.println(e.getMessage()); } doc.addUndoableEditListener(undoHandler); // we are done... get rid of progressbar status.removeAll(); status.revalidate(); resetUndoManager(); if (elementTreePanel != null) { SwingUtilities.invokeLater( new Runnable() { public void run() { elementTreePanel.setEditor(getEditor()); } }); } }
/** * This determines the amount of the progress bar that should be filled based on the percent done * gathered from the model. This is a common operation so it was abstracted out. It assumes that * your progress bar is linear. That is, if you are making a circular progress indicator, you will * want to override this method. */ protected int getAmountFull(Insets b, int width, int height) { int amountFull = 0; BoundedRangeModel model = progressBar.getModel(); if ((model.getMaximum() - model.getMinimum()) != 0) { if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { amountFull = (int) Math.round(width * progressBar.getPercentComplete()); } else { amountFull = (int) Math.round(height * progressBar.getPercentComplete()); } } return amountFull; }
@Override public void run() { setVisible(true); // 显示窗口 try { for (int i = 0; i < 100; i++) { Thread.sleep(100); // 线程休眠 jpb.setValue(jpb.getValue() + 1); // 设置进度条值 } } catch (Exception ex) { ex.printStackTrace(); } dispose(); // 释放窗口 showFrame(); // 运行主程序 }
public void tampilan_GUI() { this.getContentPane().setBackground(Color.yellow); this.getContentPane().setLayout(null); jLabel1.setFont(new java.awt.Font("Dialog", 1, 16)); jLabel1.setText("Please Waiting..."); jLabel1.setBounds(new Rectangle(14, 5, 187, 30)); prosesBar.setBounds(new Rectangle(14, 40, 311, 16)); prosesBar.setStringPainted(true); statusProses.setText(""); statusProses.setBounds(new Rectangle(14, 60, 311, 16)); this.getContentPane().add(jLabel1); this.getContentPane().add(prosesBar); this.getContentPane().add(statusProses); }
public void files(int n, int p, int np) { jProgressBarFiles.setMaximum(n); jProgressBarConvert.setMaximum(n); jProgressBarNoConvert.setMaximum(n); jProgressBarFiles.setValue(n); jProgressBarConvert.setValue(p); jProgressBarNoConvert.setValue(np); jProgressBarFiles.setString((new Integer(n)).toString()); jProgressBarConvert.setString((new Integer(p)).toString()); jProgressBarNoConvert.setString((new Integer(np)).toString()); }
/** * When the worker needs to update the GUI we do so by queuing a Runnable for the event * dispatching thread with SwingUtilities.invokeLater(). In this case we're just changing the * progress bars value. */ void updateStatus(final String t, final int i) { if (this.progressBar != null) { Runnable doSetProgressBarValue = () -> progressBar.setValue(i); SwingUtilities.invokeLater(doSetProgressBarValue); } this.currentState.setText(t); }
/** * Stores the position and size of the bouncing box that would be painted for the current * animation index in <code>r</code> and returns <code>r</code>. Subclasses that add to the * painting performed in this class's implementation of <code>paintIndeterminate</code> -- to draw * an outline around the bouncing box, for example -- can use this method to get the location of * the bouncing box that was just painted. By overriding this method, you have complete control * over the size and position of the bouncing box, without having to reimplement <code> * paintIndeterminate</code>. * * @param r the Rectangle instance to be modified; may be <code>null</code> * @return <code>null</code> if no box should be drawn; otherwise, returns the passed-in rectangle * (if non-null) or a new rectangle * @see #setAnimationIndex * @since 1.4 */ protected Rectangle getBox(Rectangle r) { int currentFrame = getAnimationIndex(); int middleFrame = numFrames / 2; if (sizeChanged() || delta == 0.0 || maxPosition == 0.0) { updateSizes(); } r = getGenericBox(r); if (r == null) { return null; } if (middleFrame <= 0) { return null; } // assert currentFrame >= 0 && currentFrame < numFrames if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { if (currentFrame < middleFrame) { r.x = componentInnards.x + (int) Math.round(delta * (double) currentFrame); } else { r.x = maxPosition - (int) Math.round(delta * (currentFrame - middleFrame)); } } else { // VERTICAL indeterminate progress bar if (currentFrame < middleFrame) { r.y = componentInnards.y + (int) Math.round(delta * currentFrame); } else { r.y = maxPosition - (int) Math.round(delta * (currentFrame - middleFrame)); } } return r; }
/** * Returns the spacing between each of the cells/units in the progress bar. However, for text * rendering simplification and aesthetic considerations, this function will return 0 when the * progress string is being rendered. * * @return the value representing the spacing between cells * @see #setCellSpacing * @see JProgressBar#isStringPainted */ protected int getCellSpacing() { if (progressBar.isStringPainted()) { return 0; } else { return cellSpacing; } }
/** Get ready for a new game, given a letter list specification of the Boggle board. */ public void newGame() { myBoard = BoggleBoardFactory.getBoard(myBoardSize); mySeconds = 0; myProgress.setValue(0); // set up views for new game if (myBoardSize == 4) { if (myBoardPanel != myBoardPanel4) { myBoardPanel = myBoardPanel4; getContentPane().remove(myBoardPanel5); getContentPane().add(myBoardPanel, BorderLayout.CENTER); } } else { if (myBoardPanel != myBoardPanel5) { myBoardPanel = myBoardPanel5; getContentPane().remove(myBoardPanel4); getContentPane().add(myBoardPanel, BorderLayout.CENTER); } } myBoardPanel.newGame(); humanArea.setReady(); computerArea.setReady(); myBoardPanel.unHighlightAllDice(); wordEntryField.setReady(); ((JPanel) getContentPane()).revalidate(); repaint(); myTimer.start(); }
/** Invoked by PropertyChangeHandler. */ private void cleanUpIndeterminateValues() { // stop the animation thread if necessary if (progressBar.isDisplayable()) { stopAnimationTimer(); } cycleTime = repaintInterval = 0; numFrames = animationIndex = 0; maxPosition = 0; delta = 0.0; boxRect = nextPaintRect = null; componentInnards = oldComponentInnards = null; progressBar.removeHierarchyListener(getHandler()); }
protected void initComponents() { int border = 2; this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); // Description label JPanel descriptionPanel = new JPanel(new GridLayout(0, 1, 0, 0)); descriptionPanel.setBorder(BorderFactory.createEmptyBorder(border, border, border, border)); String text = thread.getRetrievable().getName(); text = text.length() > 40 ? text.substring(0, 37) + "..." : text; descriptionLabel = new JLabel(text); descriptionPanel.add(descriptionLabel); this.add(descriptionPanel); // Progrees and cancel button JPanel progressPanel = new JPanel(); progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.X_AXIS)); progressPanel.setBorder(BorderFactory.createEmptyBorder(border, border, border, border)); progressBar = new JProgressBar(0, 100); progressBar.setPreferredSize(new Dimension(100, 16)); progressPanel.add(progressBar); progressPanel.add(Box.createHorizontalStrut(8)); cancelButton = new JButton("Cancel"); cancelButton.setBackground(Color.RED); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { cancelButtonActionPerformed(event); } }); progressPanel.add(cancelButton); this.add(progressPanel); }
/** Assumes that the component innards, max position, etc. are up-to-date. */ private Rectangle getGenericBox(Rectangle r) { if (r == null) { r = new Rectangle(); } if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { r.width = getBoxLength(componentInnards.width, componentInnards.height); if (r.width < 0) { r = null; } else { r.height = componentInnards.height; r.y = componentInnards.y; } // end of HORIZONTAL } else { // VERTICAL progress bar r.height = getBoxLength(componentInnards.height, componentInnards.width); if (r.height < 0) { r = null; } else { r.width = componentInnards.width; r.x = componentInnards.x; } } // end of VERTICAL return r; }
/** * Returns the width (if HORIZONTAL) or height (if VERTICAL) of each of the individual cells/units * to be rendered in the progress bar. However, for text rendering simplification and aesthetic * considerations, this function will return 1 when the progress string is being rendered. * * @return the value representing the spacing between cells * @see #setCellLength * @see JProgressBar#isStringPainted */ protected int getCellLength() { if (progressBar.isStringPainted()) { return 1; } else { return cellLength; } }
/** Delegates painting to one of two methods: paintDeterminate or paintIndeterminate. */ public void paint(Graphics g, JComponent c) { if (progressBar.isIndeterminate()) { paintIndeterminate(g, c); } else { paintDeterminate(g, c); } }
private JPanel createToolPanel() { configurationOverrideCombo.setModel(configurationOverrideModel); final int preferredHeight = configurationOverrideCombo.getPreferredSize().height; configurationOverrideCombo.setPreferredSize(new Dimension(250, preferredHeight)); configurationOverrideCombo.setMaximumSize(new Dimension(350, preferredHeight)); treeModel = new ResultTreeModel(); resultsTree = new Tree(treeModel); resultsTree.setRootVisible(false); final TreeSelectionListener treeSelectionListener = new ToolWindowSelectionListener(); resultsTree.addTreeSelectionListener(treeSelectionListener); final MouseListener treeMouseListener = new ToolWindowMouseListener(); resultsTree.addMouseListener(treeMouseListener); resultsTree.setCellRenderer(new ResultTreeRenderer()); progressLabel = new JLabel(" "); progressBar = new JProgressBar(JProgressBar.HORIZONTAL); progressBar.setMinimum(0); final Dimension progressBarSize = new Dimension(100, progressBar.getPreferredSize().height); progressBar.setMinimumSize(progressBarSize); progressBar.setPreferredSize(progressBarSize); progressBar.setMaximumSize(progressBarSize); progressPanel = new JToolBar(JToolBar.HORIZONTAL); progressPanel.add(Box.createHorizontalStrut(4)); progressPanel.add(new JLabel(CheckStyleBundle.message("plugin.toolwindow.override"))); progressPanel.add(Box.createHorizontalStrut(4)); progressPanel.add(configurationOverrideCombo); progressPanel.add(Box.createHorizontalStrut(4)); progressPanel.addSeparator(); progressPanel.add(Box.createHorizontalStrut(4)); progressPanel.add(progressLabel); progressPanel.add(Box.createHorizontalGlue()); progressPanel.setFloatable(false); progressPanel.setBackground(UIManager.getColor("Panel.background")); progressPanel.setBorder(null); final JPanel toolPanel = new JPanel(new BorderLayout()); toolPanel.add(new JBScrollPane(resultsTree), BorderLayout.CENTER); toolPanel.add(progressPanel, BorderLayout.NORTH); ToolTipManager.sharedInstance().registerComponent(resultsTree); return toolPanel; }
SwingProgress() { super(new BorderLayout()); progress = new JProgressBar(); progress.setStringPainted(true); SwingProgress.this.add(BorderLayout.NORTH, progress); }