Java Code Examples for javax.swing.JProgressBar#setPreferredSize()

The following examples show how to use javax.swing.JProgressBar#setPreferredSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SplashScreen.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @throws HeadlessException
 */
public SplashScreen(final JFrame parent, final boolean showImage, final int startupStepsCount) throws HeadlessException {
	super(parent, ModalityType.APPLICATION_MODAL);
	final String version = Resources.getVersion();
	if (showImage) {
		final Image image = Resources.getImageIcon("splashscreen.jpg").getImage();
		getContentPane().add(new ImageComponent(image, new String[] { "Open Visual Traceroute", version + "                   Leo Lewis" }), BorderLayout.CENTER);
	}
	_progress = new JProgressBar(1, startupStepsCount);
	_progress.setIndeterminate(false);
	_progress.setStringPainted(true);
	_progress.setPreferredSize(new Dimension(500, _progress.getPreferredSize().height));
	getContentPane().add(_progress, BorderLayout.SOUTH);
	setFocusable(false);
	setUndecorated(true);
	pack();
	setLocationRelativeTo(null);
}
 
Example 2
Source File: Convertor.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addStep(ConvertStep step, List<ConvertStep> steps, JComponent panel, GridBagLayout layout, GridBagConstraints c) {
    JLabel title = new JLabel(step.getDescription());
    JProgressBar progress = step.getProgressBar();
    JComponent status = step.getStatusComponent();

    c.gridx = 0;
    c.weightx = 1;
    layout.setConstraints(title, c);
    panel.add(title);
    c.gridx = 1;
    c.weightx = 0;
    layout.setConstraints(progress, c);
    panel.add(progress);
    c.gridx = 2;
    c.weightx = 1;
    layout.setConstraints(status, c);
    panel.add(status);
    ++c.gridy;
    progress.setPreferredSize(new Dimension(PROGRESS_WIDTH, PROGRESS_HEIGHT));
    status.setPreferredSize(new Dimension(STATUS_WIDTH, STATUS_HEIGHT));

    steps.add(step);
}
 
Example 3
Source File: ProgressWindow.java    From pcap-burp with GNU Affero General Public License v3.0 6 votes vote down vote up
public ProgressWindow(JFrame parent, String title, String message) {
	super(parent, title, true);
	if (parent != null) {
		Dimension parentSize = parent.getSize();
		Point p = parent.getLocation();
		setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
	}
	JPanel messagePane = new JPanel();
	label = new JLabel(message);
	messagePane.add(label);
	getContentPane().add(messagePane);

	JPanel progressPane = new JPanel();
	progressBar = new JProgressBar(0, 100);
	progressBar.setIndeterminate(true);
	progressBar.setPreferredSize(new Dimension(250, 20));
	progressBar.setVisible(true);
	progressPane.add(progressBar);

	getContentPane().add(progressPane, BorderLayout.SOUTH);
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	pack();
}
 
Example 4
Source File: DesktopHelper.java    From pumpernickel with MIT License 5 votes vote down vote up
private void createDialog(boolean pack) {
	JProgressBar progressBar = new JProgressBar();
	progressBar.setIndeterminate(true);

	Dimension d = progressBar.getPreferredSize();
	if (d.width < 250) {
		d.width = 250;
		progressBar.setPreferredSize(d);
	}

	JPanel content = new JPanel(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.gridx = 0;
	c.gridy = 0;
	c.weightx = 1;
	c.weighty = 1;
	c.fill = GridBagConstraints.BOTH;
	c.insets = new Insets(3, 3, 3, 3);
	content.add(new JLabel(labelMsg), c);
	c.gridx++;
	c.weightx = 0;
	content.add(new JThrobber(), c);
	c.gridy++;
	c.gridx = 0;
	c.gridwidth = 2;
	content.add(progressBar, c);

	footer = DialogFooter.createDialogFooter(
			DialogFooter.OK_CANCEL_OPTION,
			EscapeKeyBehavior.TRIGGERS_DEFAULT);
	footer.getButton(DialogFooter.CANCEL_OPTION).setEnabled(false);
	footer.getButton(DialogFooter.OK_OPTION).setVisible(false);
	dialog = new QDialog(frame, dialogTitle, null, content, footer,
			false);
	if (pack)
		dialog.pack();
	dialog.setLocationRelativeTo(null);
}
 
Example 5
Source File: StatusBar.java    From tda with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * create the memory status panel, also includes a resize icon on the lower right
 */
private JPanel createMemoryStatus() {
    memStatus = new JProgressBar(0, 100);
    memStatus.setPreferredSize(new Dimension(100, 15));
    memStatus.setStringPainted(true);
    JPanel memPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    memPanel.add(memStatus);
    
    // Start Updater
    new Thread(new MemoryStatusUpdater(memStatus)).start();
    
    return memPanel;
}
 
Example 6
Source File: ProgressDialog.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: StatusPanel.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
public Progress(UpdateType updateType, ProgressControl progressShow) {
	this.updateType = updateType;
	this.progressControl = progressShow;
	switch (updateType) {
		case STRUCTURE:
			text = DialoguesStructure.get().updateTitle();
			break;
		case PUBLIC_MARKET_ORDERS:
			text = TabsOrders.get().updateTitle();
			break;
		default:
			text = "";
	}
	jProgress = new JProgressBar(0, 100);
	Dimension size = new Dimension(Program.getButtonsWidth() * 2, Program.getButtonsHeight());
	jProgress.setMinimumSize(size);
	jProgress.setPreferredSize(size);
	jProgress.setMaximumSize(size);
	jProgress.setVisible(false);
	
	jProgress.setStringPainted(true);
	if (progressShow.isAuto()) {
		jProgress.setString(text);
	} else {
		jProgress.setString(GuiFrame.get().clickToShow(text));
		jProgress.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				progressShow.show();
			}
		});
	}
}
 
Example 8
Source File: GuiMain.java    From google-sites-liberation with Apache License 2.0 5 votes vote down vote up
private void initProgressFrame() {
  progressFrame = new JFrame("Progress");
  JPanel mainPanel = new JPanel();
  mainPanel.setLayout(new BorderLayout());
  progressBar = new JProgressBar();
  progressBar.setMinimum(0);
  progressBar.setMaximum(100);
  progressBar.setPreferredSize(new Dimension(500, 25));
  JPanel progressPanel = new JPanel();
  progressPanel.add(progressBar);
  progressPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
  mainPanel.add(progressPanel, BorderLayout.NORTH);
  textArea = new JTextArea();
  textArea.setRows(20);
  textArea.setEditable(false);
  JScrollPane scrollPane = new JScrollPane(textArea);
  scrollPane.setBorder(new EmptyBorder(10, 10, 10, 10));
  mainPanel.add(scrollPane, BorderLayout.CENTER);
  doneButton = new JButton("Done");
  doneButton.setPreferredSize(new Dimension(495, 25));
  doneButton.setEnabled(false);
  doneButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      doneButton.setEnabled(false);
      progressFrame.setVisible(false);
      optionsFrame.setVisible(true);
    }
  });
  JPanel donePanel = new JPanel();
  donePanel.setLayout(new BorderLayout());
  donePanel.add(doneButton, BorderLayout.CENTER);
  donePanel.setBorder(new EmptyBorder(0, 10, 10, 10));
  mainPanel.add(donePanel, BorderLayout.SOUTH);
  progressFrame.getContentPane().add(mainPanel);
  progressFrame.pack();
  progressFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 9
Source File: ProgressDialog.java    From GpsPrune with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Make the dialog components
 * @return the GUI components for the dialog
 */
private Component makeDialogComponents()
{
	JPanel dialogPanel = new JPanel();
	dialogPanel.setLayout(new BorderLayout());
	dialogPanel.add(new JLabel(I18nManager.getText("confirm.running")), BorderLayout.NORTH);
	// Centre panel with an empty border
	JPanel centrePanel = new JPanel();
	centrePanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
	centrePanel.setLayout(new BorderLayout());
	_progressBar = new JProgressBar();
	_progressBar.setPreferredSize(new Dimension(250, 30));
	centrePanel.add(_progressBar, BorderLayout.CENTER);
	dialogPanel.add(centrePanel, BorderLayout.CENTER);
	// Cancel button at the bottom
	JPanel buttonPanel = new JPanel();
	buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
	JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
	cancelButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			_cancelled = true;
			_dialog.dispose();
		}
	});
	buttonPanel.add(cancelButton);
	dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
	return dialogPanel;
}
 
Example 10
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addRunProgress(JToolBar mainToolBar, Insets margin) {
	progressBar = new JProgressBar( 0, 100 );
	progressBar.setPreferredSize( new Dimension( 120, controlRealTime.getPreferredSize().height ) );
	progressBar.setValue( 0 );
	progressBar.setStringPainted( true );
	progressBar.setToolTipText(formatToolTip("Run Progress",
			"Percent of the present simulation run that has been completed."));
	mainToolBar.add( progressBar );
}
 
Example 11
Source File: UpdateIDE.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public ProgressBar() {
     frame = new JFrame("APICloud Studio\u66F4\u65B0\u7BA1\u7406\u5668");
     frame.setBounds(100, 100, 400, 130);
     frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
     frame.setResizable(false);
     Image image= null;
try {
  	InputStream is=UpdateIDE.class.getResourceAsStream("32_32.png");    
	image = ImageIO.read(is);
} catch (IOException e) {
	e.printStackTrace();
}
if(image != null) {
	frame.setIconImage(image);
}

     Container contentPanel = frame.getContentPane();
     JLabel label_txt = new JLabel("\u7A0B\u5E8F\u66F4\u65B0\u4E2D\uFF0C\u8BF7\u4E0D\u8981\u624B\u52A8\u542F\u52A8APICloud Studio\u4EE5\u514D\u66F4\u65B0\u5931\u8D25\uFF01", JLabel.CENTER);
    
     label_txt.setForeground(Color.red);
     label = new JLabel("", JLabel.CENTER);
     progressbar = new JProgressBar();
     progressbar.setOrientation(JProgressBar.HORIZONTAL);
     progressbar.setMinimum(0);
     progressbar.setMaximum(100);
     progressbar.setValue(0);
     progressbar.setStringPainted(true);
     progressbar.addChangeListener(this);
     progressbar.setPreferredSize(new Dimension(300, 20));
     progressbar.setBorderPainted(true);
     progressbar.setBackground(Color.green);

     timer = new Timer(700, this);
     contentPanel.add(label_txt, BorderLayout.NORTH);
     contentPanel.add(label, BorderLayout.CENTER);
     contentPanel.add(progressbar, BorderLayout.SOUTH);
     frame.setVisible(true);
     timer.start();
  }
 
Example 12
Source File: TabPanelMaintenance.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
		 * Constructor.
		 * 
		 * @param building the building to display.
		 */
		public BuildingMaintenancePanel(Building building) {
			// User WebPanel constructor.
			super();

			manager = building.getMalfunctionManager();

			setLayout(new GridLayout(4, 1, 0, 0));
//			setBorder(new MarsPanelBorder());

			WebLabel buildingLabel = new WebLabel(building.getNickName(), WebLabel.LEFT);
			buildingLabel.setFont(new Font("Serif", Font.BOLD, 14));
			add(buildingLabel);

			// Add wear condition cache and label.
			wearConditionCache = (int) Math.round(manager.getWearCondition());
			wearConditionLabel = new WebLabel(
					Msg.getString("BuildingPanelMaintenance.wearCondition", wearConditionCache),
					WebLabel.CENTER);
			TooltipManager.setTooltip(wearConditionLabel, 
					Msg.getString("BuildingPanelMaintenance.wear.toolTip"),
					TooltipWay.down);
			// wearConditionLabel.setMargin (4);
//			add(wearConditionLabel);

			WebPanel mainPanel = new WebPanel(new BorderLayout(0, 0));
			add(mainPanel);

			lastCompletedCache = (int) (manager.getTimeSinceLastMaintenance() / 1000D);
			lastLabel = new WebLabel("Last completed : " + lastCompletedCache + " sols ago", WebLabel.LEFT);
			mainPanel.add(lastLabel, BorderLayout.WEST);
			// lastLabel.setToolTipText(getToolTipString());
			TooltipManager.setTooltip(lastLabel, getToolTipString(), TooltipWay.down);

			// Prepare progress bar panel.
			WebPanel progressBarPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
//			mainPanel.add(progressBarPanel, BorderLayout.CENTER);
			add(progressBarPanel);
			
			mainPanel.add(wearConditionLabel, BorderLayout.CENTER);
			
			// Prepare progress bar.
			JProgressBar progressBar = new JProgressBar();
			progressBarModel = progressBar.getModel();
			progressBar.setStringPainted(true);
			progressBar.setPreferredSize(new Dimension(240, 15));
			progressBarPanel.add(progressBar);

			// Set initial value for progress bar.
			double completed = manager.getMaintenanceWorkTimeCompleted();
			double total = manager.getMaintenanceWorkTime();
			int percentDone = (int) (100D * (completed / total));
			progressBarModel.setValue(percentDone);

			// Prepare parts label.
			Map<Integer, Integer> parts = manager.getMaintenanceParts();
			partsLabel = new WebLabel(getPartsString(parts, false), WebLabel.CENTER);
			partsLabel.setPreferredSize(new Dimension(-1, -1));
			add(partsLabel);

			TooltipManager.setTooltip(partsLabel, getPartsString(parts, false), TooltipWay.down);
		}
 
Example 13
Source File: SplashScreen.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void init(int numberOfSteps, int messageX, int messageY, Color messageColor) {
	JPanel content = new JPanel() {
		public boolean isOptimizedDrawingEnabled() {
			return false;
		}
	};
	
	content.setLayout(new OverlayLayout(content));
	content.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
	
	JPanel dynamicContent = new JPanel();
	dynamicContent.setOpaque(false);
	dynamicContent.setLayout(new GridBagLayout());
		
	message = new JLabel();
	message.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
	message.setForeground(messageColor);
	
	progressBar = new JProgressBar();
	progressBar.setPreferredSize(new Dimension(icon.getIconWidth(), 18));
	progressBar.setIndeterminate(false);
	progressBar.setMaximum(numberOfSteps);
	progressBar.setVisible(false);
	
	GridBagConstraints c = GuiUtil.setConstraints(0, 0, 1, 1, GridBagConstraints.HORIZONTAL, 5 + messageY, 5 + messageX, 0, 5);
	c.anchor = GridBagConstraints.NORTH;
	dynamicContent.add(message, c);
	
	c = GuiUtil.setConstraints(0, 1, 1, 1, GridBagConstraints.HORIZONTAL, 5, 5, 5, 5);
	c.anchor = GridBagConstraints.SOUTH;
	dynamicContent.add(progressBar, c);
	
	dynamicContent.setAlignmentX(0f);
	dynamicContent.setAlignmentY(0f);
	content.add(dynamicContent);
	
	JLabel image = new JLabel(icon);
	image.setAlignmentX(0f);
	image.setAlignmentY(0f);
	content.add(image);
	
	add(content, BorderLayout.CENTER);
	
	// center on screen
	Toolkit t = Toolkit.getDefaultToolkit();
	Insets frame_insets = t.getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration());
	int frame_insets_x = frame_insets.left + frame_insets.right;
	int frame_insets_y = frame_insets.bottom + frame_insets.top;
	
	Dimension dim = t.getScreenSize();
	int x = (dim.width - icon.getIconWidth() - frame_insets_x) / 2;
	int y = (dim.height - icon.getIconHeight() - frame_insets_y) / 2;		
	setMinimumSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
	setLocation(x, y);
	setAlwaysOnTop(true);
}
 
Example 14
Source File: InformationDialog.java    From chipster with MIT License 4 votes vote down vote up
public InformationDialog(String title, String message, ImportScreen owner) {
		super(title);
		this.label = new JLabel(message);
		
		// This keeps the progressbar size correct after setMessage
//		label.setPreferredSize(new Dimension(
//				(int)PROGRESSBAR_SIZE.getWidth() + 100, 
//				(int)PROGRESSBAR_SIZE.getHeight()));
		label.setPreferredSize(PROGRESSBAR_SIZE);
				
		this.owner = owner;
		
		cancelButton = new JButton("Cancel");
		cancelButton.setPreferredSize(BUTTON_SIZE);
		cancelButton.addActionListener(this);
		
		progressBar = new JProgressBar();
		progressBar.setPreferredSize(PROGRESSBAR_SIZE);
		
		contentPane = new JPanel(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		
		// Label
		c.anchor = GridBagConstraints.WEST;
		c.insets.set(8, 12, 10, 4);
		c.gridx = 0; 
		c.gridy = 0;
		contentPane.add(label, c);
		
		// Combobox
		c.insets.set(0, 12, 8, 12);
		c.gridy = 1;
		contentPane.add(progressBar, c);
		
		// Buttons
		c.insets.set(4, 2, 12, 8);
		c.anchor = GridBagConstraints.EAST;
		c.gridy = 2;
		contentPane.add(cancelButton, c);
		
		logger.debug("Components on the dialog: " + contentPane.getComponentCount());
		
		this.add(contentPane);
		this.pack();
		this.setLocationRelativeTo(null);
	}