< prev index next >

src/demo/share/jfc/SwingSet2/ProgressBarDemo.java

Print this page


   1 /*
   2  *
   3  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  90         JPanel textWrapper = new JPanel(new BorderLayout());
  91         textWrapper.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
  92         textWrapper.setAlignmentX(LEFT_ALIGNMENT);
  93         progressTextArea = new MyTextArea();
  94 
  95         progressTextArea.getAccessibleContext().setAccessibleName(getString("ProgressBarDemo.accessible_text_area_name"));
  96         progressTextArea.getAccessibleContext().setAccessibleName(getString("ProgressBarDemo.accessible_text_area_description"));
  97         textWrapper.add(new JScrollPane(progressTextArea), BorderLayout.CENTER);
  98 
  99         getDemoPanel().add(textWrapper, BorderLayout.CENTER);
 100 
 101         JPanel progressPanel = new JPanel();
 102         getDemoPanel().add(progressPanel, BorderLayout.SOUTH);
 103 
 104         progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, text.length()) {
 105             public Dimension getPreferredSize() {
 106                 return new Dimension(300, super.getPreferredSize().height);
 107             }
 108         };
 109         progressBar.getAccessibleContext().setAccessibleName(getString("ProgressBarDemo.accessible_text_loading_progress"));

 110 
 111         progressPanel.add(progressBar);
 112         progressPanel.add(createLoadButton());
 113         progressPanel.add(createStopButton());
 114     }
 115 
 116     public JButton createLoadButton() {
 117         loadAction = new AbstractAction(getString("ProgressBarDemo.start_button")) {
 118             public void actionPerformed(ActionEvent e) {
 119                 loadAction.setEnabled(false);
 120                 stopAction.setEnabled(true);
 121                 if (progressBar.getValue() == progressBar.getMaximum()) {
 122                     progressBar.setValue(0);
 123                     textLocation = 0;
 124                     progressTextArea.setText("");
 125                 }
 126                 timer.start();
 127             }
 128         };
 129         return createButton(loadAction);


   1 /*
   2  *
   3  * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  90         JPanel textWrapper = new JPanel(new BorderLayout());
  91         textWrapper.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
  92         textWrapper.setAlignmentX(LEFT_ALIGNMENT);
  93         progressTextArea = new MyTextArea();
  94 
  95         progressTextArea.getAccessibleContext().setAccessibleName(getString("ProgressBarDemo.accessible_text_area_name"));
  96         progressTextArea.getAccessibleContext().setAccessibleName(getString("ProgressBarDemo.accessible_text_area_description"));
  97         textWrapper.add(new JScrollPane(progressTextArea), BorderLayout.CENTER);
  98 
  99         getDemoPanel().add(textWrapper, BorderLayout.CENTER);
 100 
 101         JPanel progressPanel = new JPanel();
 102         getDemoPanel().add(progressPanel, BorderLayout.SOUTH);
 103 
 104         progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, text.length()) {
 105             public Dimension getPreferredSize() {
 106                 return new Dimension(300, super.getPreferredSize().height);
 107             }
 108         };
 109         progressBar.getAccessibleContext().setAccessibleName(getString("ProgressBarDemo.accessible_text_loading_progress"));
 110         progressBar.setFocusable(true);
 111 
 112         progressPanel.add(progressBar);
 113         progressPanel.add(createLoadButton());
 114         progressPanel.add(createStopButton());
 115     }
 116 
 117     public JButton createLoadButton() {
 118         loadAction = new AbstractAction(getString("ProgressBarDemo.start_button")) {
 119             public void actionPerformed(ActionEvent e) {
 120                 loadAction.setEnabled(false);
 121                 stopAction.setEnabled(true);
 122                 if (progressBar.getValue() == progressBar.getMaximum()) {
 123                     progressBar.setValue(0);
 124                     textLocation = 0;
 125                     progressTextArea.setText("");
 126                 }
 127                 timer.start();
 128             }
 129         };
 130         return createButton(loadAction);


< prev index next >