下面列出了javax.swing.plaf.basic.BasicProgressBarUI#javax.swing.JProgressBar 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected JPanel assemble() {
progress = new JProgressBar();
status = new HyperTextPane(" ")
.withTransparency().withWidth(400);
JPanel ret = new JPanel();
ret.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.NONE;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets.top = 20;
ret.add(progress, gbc);
gbc.weighty = 1;
gbc.gridy++;
gbc.fill = GridBagConstraints.BOTH;
ret.add(status, gbc);
return ret;
}
PCGenStatusBar(PCGenFrame frame)
{
this.frame = frame;
this.messageLabel = new JLabel();
this.progressBar = new JProgressBar();
this.loadStatusButton = new Button();
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
add(messageLabel);
add(Box.createHorizontalGlue());
progressBar.setStringPainted(true);
progressBar.setVisible(false);
add(progressBar);
add(Box.createHorizontalGlue());
JFXPanel wrappedButton = GuiUtility.wrapParentAsJFXPanel(loadStatusButton);
//todo: calculate this rather than hard code
wrappedButton.setMaximumSize(new Dimension(750, 20000000));
add(wrappedButton);
loadStatusButton.setOnAction(this::loadStatusLabelAction);
}
private static Component newContent(final String message) {
final JPanel panel = new JPanel();
panel.setBorder(new LineBorder(Color.BLACK));
panel.setLayout(new BorderLayout());
final JLabel label = new JLabel(message);
label.setBorder(new EmptyBorder(10, 10, 10, 10));
panel.add(BorderLayout.NORTH, label);
final JProgressBar progressBar = new JProgressBar();
progressBar.setBorder(new EmptyBorder(10, 10, 10, 10));
progressBar.setIndeterminate(true);
panel.add(progressBar, BorderLayout.CENTER);
return panel;
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
/**
Construct a collapse simulator GUI.
*/
public CollapseSimulatorGUI() {
super(new GridLayout(0, 2));
timeLabel = new JLabel("Not started");
statusLabel = new JLabel("Not started");
collapseProgress = new JProgressBar(0, 1);
fireProgress = new JProgressBar(0, 1);
blockadeProgress = new JProgressBar(0, 1);
collapseProgress.setStringPainted(true);
fireProgress.setStringPainted(true);
blockadeProgress.setStringPainted(true);
add(new JLabel("Timestep"));
add(timeLabel);
add(new JLabel("Status"));
add(statusLabel);
add(new JLabel("Collapsing buildings"));
add(collapseProgress);
add(new JLabel("Fire damage"));
add(fireProgress);
add(new JLabel("Creating blockades"));
add(blockadeProgress);
}
/**
* Create a new instance of StartupPanel
* @param gameModeFileLoader
* @param campaignFileLoader
*/
public StartupPanel(GameModeFileLoader gameModeFileLoader, CampaignFileLoader campaignFileLoader)
{
this.gameModeFileLoader = gameModeFileLoader;
this.campaignFileLoader = campaignFileLoader;
message = new JPanel();
message.setLayout(new UnstretchingGridLayout(0, 1));
message
.add(new JLabel("Welcome to the PCGen " + PCGenPropBundle.getProdVersionSeries() + " Data Converter..."));
message.add(new JLabel(" "));
message.add(new JLabel("Loading Game Modes and Campaign Information."));
message.add(new JLabel(" "));
progressBar = new JProgressBar(0, 3);
progressBar.setValue(0);
progressBar.setStringPainted(true);
message.add(progressBar);
message.add(new JLabel(" "));
}
private static void executeTestCase(String lookAndFeelString) throws Exception{
if (tryLookAndFeel(lookAndFeelString)) {
EventQueue.invokeAndWait( new Runnable() {
@Override
public void run() {
showUI();
}
} );
EventQueue.invokeAndWait( new Runnable() {
@Override
public void run() {
disposeUI();
}
} );
Util.generateOOME();
JProgressBar progressBar = sProgressBar.get();
if ( progressBar != null ) {
throw new RuntimeException( "Progress bar (using L&F: " + lookAndFeelString + ") should have been GC-ed" );
}
}
}
private PrintPreviewDialog(PCGenFrame frame)
{
super(frame, true);
this.frame = frame;
this.character = frame.getSelectedCharacterRef().get();
this.previewPanelParent = new JPanel(new GridLayout(1, 1));
this.sheetBox = new JComboBox<>();
this.progressBar = new JProgressBar();
this.pageBox = new JComboBox<>();
this.zoomBox = new JComboBox<>();
this.zoomInButton = new JButton();
this.zoomOutButton = new JButton();
this.printButton = new JButton();
this.cancelButton = new JButton();
initComponents();
initLayout();
pack();
new SheetLoader().execute();
}
/**
* Create a new instance of StartupPanel
* @param gameModeFileLoader
* @param campaignFileLoader
*/
public StartupPanel(GameModeFileLoader gameModeFileLoader, CampaignFileLoader campaignFileLoader)
{
this.gameModeFileLoader = gameModeFileLoader;
this.campaignFileLoader = campaignFileLoader;
message = new JPanel();
message.setLayout(new UnstretchingGridLayout(0, 1));
message
.add(new JLabel("Welcome to the PCGen " + PCGenPropBundle.getProdVersionSeries() + " Data Converter..."));
message.add(new JLabel(" "));
message.add(new JLabel("Loading Game Modes and Campaign Information."));
message.add(new JLabel(" "));
progressBar = new JProgressBar(0, 3);
progressBar.setValue(0);
progressBar.setStringPainted(true);
message.add(progressBar);
message.add(new JLabel(" "));
}
public StatusBar() {
Font font = new Font("Arial", Font.PLAIN, FontSize.getGuiFontSize());
setLayout(new BorderLayout(10, 0));
progressBar = new JProgressBar();
statusLabel = new JLabel();
statusLabel.setFont(font);
statusLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (ex != null) {
ErrorDialog.show(ex);
}
if (warnings != null) {
displayWarnings();
}
}
});
setStatus("Ready");
add(statusLabel, BorderLayout.WEST);
add(progressBar, BorderLayout.CENTER);
add(new JLabel(spacer), BorderLayout.EAST);
}
private static void watchProgressBar(TestData data, JFrameOperator frame, String label) {
new JLabelOperator(frame, label); //dirty hack
JProgressBarOperator progressBar = new JProgressBarOperator(frame);
long waitingTime;
for (waitingTime = 0; waitingTime < Utils.MAX_INSTALATION_WAIT; waitingTime += Utils.DELAY) {
int val = ((JProgressBar) progressBar.getSource()).getValue();
if (val >= 100) {
break;
}
Utils.waitSecond(data, 5);
}
if (waitingTime >= Utils.MAX_INSTALATION_WAIT) {
TestCase.fail("Installation timeout");
}
}
@RandomlyFails // NB-Core-Build #1176
public void testCustomComponentIsInitialized() {
Controller.defaultInstance = new TestController();
ProgressHandle handle = ProgressHandleFactory.createHandle("task 1");
// Warning, this will make the handle to work with a new Controller, not TestController.
JComponent component = ProgressHandleFactory.createProgressComponent(handle);
handle.start(15);
handle.progress(2);
waitForTimerFinish();
assertEquals(15, ((JProgressBar) component).getMaximum());
assertEquals(2, ((JProgressBar) component).getValue());
handle = ProgressHandleFactory.createHandle("task 2");
component = ProgressHandleFactory.createProgressComponent(handle);
handle.start(20);
waitForTimerFinish();
assertEquals(20, ((JProgressBar) component).getMaximum());
assertEquals(0, ((JProgressBar) component).getValue());
}
/**
* Create the frame.
*/
public SendFileFrame()
{
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 510, 196);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
lbl = new JLabel("进度条");
lbl.setBounds(42, 35, 74, 33);
contentPane.add(lbl);
progressBar = new JProgressBar();
progressBar.setForeground(Color.BLUE);
progressBar.setBounds(96, 35, 332, 33);
contentPane.add(progressBar);
lblProgress = new JLabel("");
lblProgress.setBounds(64, 82, 386, 58);
contentPane.add(lblProgress);
}
private static void executeTestCase(String lookAndFeelString) throws Exception{
if (tryLookAndFeel(lookAndFeelString)) {
EventQueue.invokeAndWait( new Runnable() {
@Override
public void run() {
showUI();
}
} );
EventQueue.invokeAndWait( new Runnable() {
@Override
public void run() {
disposeUI();
}
} );
Util.generateOOME();
JProgressBar progressBar = sProgressBar.get();
if ( progressBar != null ) {
throw new RuntimeException( "Progress bar (using L&F: " + lookAndFeelString + ") should have been GC-ed" );
}
}
}
public ProgressPanel(final MainWindow mainWindow, boolean showCancelButton) {
this.showCancelButton = showCancelButton;
progressLabel = new JLabel();
progressBar = new JProgressBar(0, 100);
progressBar.setIndeterminate(true);
progressBar.setStringPainted(false);
progressLabel.setLabelFor(progressBar);
setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
setVisible(false);
add(progressLabel);
add(progressBar);
cancelButton = new JButton(ICON_CANCEL);
cancelButton.setPreferredSize(new Dimension(ICON_CANCEL.getIconWidth(), ICON_CANCEL.getIconHeight()));
cancelButton.setToolTipText("Cancel background jobs");
cancelButton.setBorderPainted(false);
cancelButton.setFocusPainted(false);
cancelButton.setContentAreaFilled(false);
cancelButton.addActionListener(e -> mainWindow.cancelBackgroundJobs());
cancelButton.setVisible(showCancelButton);
add(cancelButton);
}
private static void executeTestCase(String lookAndFeelString) throws Exception{
if (tryLookAndFeel(lookAndFeelString)) {
EventQueue.invokeAndWait( new Runnable() {
@Override
public void run() {
showUI();
}
} );
EventQueue.invokeAndWait( new Runnable() {
@Override
public void run() {
disposeUI();
}
} );
Util.generateOOME();
JProgressBar progressBar = sProgressBar.get();
if ( progressBar != null ) {
throw new RuntimeException( "Progress bar (using L&F: " + lookAndFeelString + ") should have been GC-ed" );
}
}
}
/**
* Initializes a new instance of the {@code ProgressWindow} class.
*
* @param owner The frame from which the window is displayed; if {@code null} the shared owner
* will be used and this window will not be focusable.
* @param title The progress message; may be {@code null}.
*/
public ProgressWindow(final Frame owner, final String title) {
super(owner);
final JLabel label = new JLabel(title);
label.setBorder(new EmptyBorder(10, 10, 10, 10));
final JProgressBar progressBar = new JProgressBar();
progressBar.setBorder(new EmptyBorder(10, 10, 10, 10));
progressBar.setIndeterminate(true);
final JPanel panel = new JPanel();
panel.setBorder(new LineBorder(Color.BLACK));
panel.setLayout(new BorderLayout());
panel.add(BorderLayout.NORTH, label);
panel.add(progressBar, BorderLayout.CENTER);
setLayout(new BorderLayout());
setSize(200, 80);
add(panel, BorderLayout.CENTER);
pack();
setLocationRelativeTo(owner);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static void createUI(final String shortenedLookAndFeelString)
throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
progressBar = new JProgressBar();
progressBar.setValue(30);
frame = new JFrame(shortenedLookAndFeelString);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(progressBar);
frame.pack();
frame.setSize(500, frame.getSize().height);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.toFront();
}
});
}
/**
* Creates a progress bar.
*
* @param parent progress bar's parent. The horizontal axis of the progress bar will be center-aligned to the parent.
* @return a progress bar.
*/
private static JProgressBar createProgressBar(final JComponent parent) {
final JProgressBar progressBar = new JProgressBar();
progressBar.setSize(260, 20);
parent.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
progressBar.setLocation(
parent.getWidth() / 2 - progressBar.getWidth() / 2,
parent.getHeight() - progressBar.getHeight() - 20);
}
});
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
progressBar.setVisible(false);
return progressBar;
}
public StatusDialog(Controller ctrl) {
super(ctrl.getContainer());
// store controller reference
this.ctrl = ctrl;
//dialog = new JDialog();
setTitle("Working...");
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1; c.weighty = 1;
c.insets = new Insets(5,5,5,5);
add(lblStatus = new JLabel(), c);
c.gridy++;
c.weighty = 1.5;
add(progress = new JProgressBar(0,1000), c);
c.gridy++;
c.weighty = 0.5;
c.fill = GridBagConstraints.NONE;
add(btnAbort = new JButton("Abort"),c);
btnAbort.addActionListener(this);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
setResizable(false);
pack();
setSize(220,120);
setVisible(true);
}
private void setProgressValues (JProgressBar pb, JLabel lbl, double value, String msg)
{
if (!pb.isVisible())
return ;
int pbVal = Math.min((int) (value * 100), 100) ;
if (pb.isIndeterminate())
pb.setIndeterminate(false) ;
pb.setValue(pbVal);
lbl.setText((msg == null)?(""):(msg));
}
/**
* Constructor
*
* @param progressBar The progress bar this has to update
*/
public ProgressDialog(Window parent, String dialogTitle) {
super(parent, dialogTitle, ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
setResizable(false);
bundle = java.util.ResourceBundle.getBundle("course_generator/Bundle");
Container paneGlobal = getContentPane();
paneGlobal.setLayout(new GridBagLayout());
// -- Progress bar
progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setPreferredSize(new Dimension(500, 30));
Utils.addComponent(paneGlobal, progressBar, 0, 0, 1, 1, 0, 0, 10, 10, 10, 10,
GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
// -- Cancel button
buttonCancel = new JButton(bundle.getString("Global.btCancel.text"));
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (progressDialogListener != null) {
progressDialogListener.progressDialogCancelled();
}
}
});
Utils.addComponent(paneGlobal, buttonCancel, 0, 1, 1, 1, 0, 0, 0, 10, 10, 10, GridBagConstraints.CENTER,
GridBagConstraints.NONE);
pack();
// -- Center the dialog on the parent
setLocationRelativeTo(parent);
}
public void addNotificationListeners(Component c) {
if (c instanceof Accessible) {
AccessibleContext ac = ((Accessible)c).getAccessibleContext();
ac.addPropertyChangeListener(new AXChangeNotifier());
}
if (c instanceof JProgressBar) {
JProgressBar pb = (JProgressBar) c;
pb.addChangeListener(new AXProgressChangeNotifier());
} else if (c instanceof JSlider) {
JSlider slider = (JSlider) c;
slider.addChangeListener(new AXProgressChangeNotifier());
}
}
@Override
protected void paintDeterminate(Graphics g, JComponent c) {
Insets b = progressBar.getInsets(); // area for border
int barRectWidth = progressBar.getWidth() - (b.right + b.left);
int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
if (barRectWidth <= 0 || barRectHeight <= 0) {
return;
}
// amount of progress to draw
int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(ColorResource.getSelectionColor());
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
g2.fillRect(0, 0, amountFull, c.getHeight());
} else { // VERTICAL
}
// Deal with possible text painting
// if (progressBar.isStringPainted()) {
// paintString(g, b.left, b.top, barRectWidth, barRectHeight,
// amountFull, b);
// }
}
/**
* @see net.sourceforge.squirrel_sql.client.update.gui.installer.ProgressDialogController#showProgressDialog(java.lang.String,
* java.lang.String, int)
*/
public void showProgressDialog(final String title, final String msg, final int total)
{
s_log.info("showing progress dialog");
GUIUtils.processOnSwingEventThread(new Runnable()
{
public void run()
{
currentDialog = new JDialog((Frame) null, title);
currentMessage = new JLabel(msg);
detailMessage = new JLabel("...");
currentProgressBar = new JProgressBar(0, total - 1);
JPanel panel = new JPanel(new BorderLayout());
JPanel messagePanel = new JPanel(new GridLayout(2,1));
messagePanel.add(currentMessage);
messagePanel.add(detailMessage);
panel.add(messagePanel, BorderLayout.CENTER);
panel.add(currentProgressBar, BorderLayout.SOUTH);
currentDialog.getContentPane().add(panel);
currentDialog.setSize(300, 100);
GUIUtils.centerWithinScreen(currentDialog);
currentDialog.setVisible(true);
}
}, true);
}
public CheckinForm(NavigateAction forward, NavigateAction backward) {
super(forward, backward);
result = new HypertextPane("");
result.setPreferredSize(new Dimension(300, 200));
result.setOpaque(false);
progress = new JProgressBar();
progress.setIndeterminate(true);
progress.setVisible(false);
setLayout(new BorderLayout());
add(result, BorderLayout.CENTER);
add(progress, BorderLayout.NORTH);
}
/**
* Maps {@code JProgressBar.setMinimum(int)} through queue
*/
public void setMinimum(final int i) {
runMapping(new MapVoidAction("setMinimum") {
@Override
public void map() {
((JProgressBar) getSource()).setMinimum(i);
}
});
}
private void initComponents() {
applyButton = new JButton("Apply");
selectAllButton = new JButton("Select all");
selectNoneButton = new JButton("Select none");
listModel = new VariableListModel();
filterField = new LabeledTextField();
filteredListModel = new FilteredListModel<>(listModel);
checkBoxList = new ToolTippedCheckBoxList(filteredListModel);
progressBar = new JProgressBar();
statusLabel = new JLabel("");
percentageLabel = new JLabel("");
pm = new VariableFilterProgressBarProgressMonitor(progressBar, statusLabel, percentageLabel);
}