當前位置: 首頁>>代碼示例>>Java>>正文


Java JProgressBar.setSize方法代碼示例

本文整理匯總了Java中javax.swing.JProgressBar.setSize方法的典型用法代碼示例。如果您正苦於以下問題:Java JProgressBar.setSize方法的具體用法?Java JProgressBar.setSize怎麽用?Java JProgressBar.setSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JProgressBar的用法示例。


在下文中一共展示了JProgressBar.setSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ProgressDialog

import javax.swing.JProgressBar; //導入方法依賴的package包/類
/**
* @param parentFrame  The parent frame.
* @param title The dialog title.
* @param modal  True if you want a modal dialog.
*/
private ProgressDialog(Frame parentFrame, String title) {
  //----------------------- modal
  super(parentFrame, title, true);
  
  setLocationRelativeTo(parentFrame);
  
  getOkButton().setVisible(false);
  
  JPanel mainPanel = new JPanel(new GridBagLayout());
  progressBar = new JProgressBar();
  label = new JLabel(resourceBundle.getMessage(Tags.PROGRESS_DIALOG_LABEL));
  
  progressBar.setValue(0);
  progressBar.setStringPainted(true);
  progressBar.setSize(300, 100);
  
  GridBagConstraints gbc1 = new GridBagConstraints();
  gbc1.gridx = 0;
  gbc1.gridy = 0;
  gbc1.gridwidth = 1;
  gbc1.gridheight = 1;
  gbc1.weightx = 1;
  gbc1.weighty = 1;
  gbc1.fill = GridBagConstraints.BOTH;
  gbc1.anchor = GridBagConstraints.CENTER;
  gbc1.ipadx = 10;
  gbc1.ipady = 10;
  
  GridBagConstraints gbc2 = new GridBagConstraints();
  gbc2.gridx = 0;
  gbc2.gridy = 1;
  gbc2.gridwidth = 1;
  gbc2.gridheight = 1;
  gbc2.weightx = 1;
  gbc2.weighty = 1;
  gbc2.fill = GridBagConstraints.BOTH;
  gbc2.anchor = GridBagConstraints.CENTER;
  gbc2.ipadx = 10;
  gbc2.ipady = 10;
  
  mainPanel.add(label, gbc1);
  mainPanel.add(progressBar, gbc2);
  
  getContentPane().add(mainPanel, BorderLayout.CENTER);
  
  pack();
  setResizable(true);

  scheduleStart();
}
 
開發者ID:oxygenxml,項目名稱:oxygen-dita-translation-package-builder,代碼行數:56,代碼來源:ProgressDialog.java

示例2: run

import javax.swing.JProgressBar; //導入方法依賴的package包/類
/**
 * thread run method
 */
public void run() {
	
	System.out.println("[ReceiveFileThread] :: started on port " + port + "file size : " + fileSize);
       int progress = 0;
	try {
		
		ServerSocket ssock = new ServerSocket(port);			
		Socket socket = ssock.accept();
		int size = 10000;
		byte[] contents = new byte[size];

		//Initialize the FileOutputStream to the output file's full path.
		FileOutputStream fos = new FileOutputStream(filePath);
		BufferedOutputStream bos = new BufferedOutputStream(fos);
		InputStream is = socket.getInputStream();

		//No of bytes read in one read() call
		int bytesRead = 0; 
       
		//receiving file Message dialog window
		JFrame recFileMessFrame =  new JFrame("Recieving File");
		recFileMessFrame.setBounds(500, 300, 350, 200);
	  			
	  	JPanel panel = new JPanel();
	  	panel.setLayout(new GridLayout(9, 1));
	  	
	 	//progress bar for recieved data
	  	JProgressBar progressbar = new JProgressBar(0, 100); 	
	  	progressbar.setSize(new Dimension(100, 15));
	    progressbar.setBackground(Color.white);
	    progressbar.setForeground(Color.gray);		    
	   
	    //adding blank frame
	    for(int i = 0; i <= 2; i++){
		    panel.add(new JPanel());
		}
	    
	    JPanel progressPanel = new JPanel(new BorderLayout(5, 5));
		JLabel progressLabel = new JLabel();
		
		//adding progress label to progress panel
		progressPanel.add(progressLabel);			
		panel.add(progressPanel);
		
	    //adding progress panel to main panel
		panel.add(progressbar);
	
		recFileMessFrame.add(panel);
		recFileMessFrame.setVisible(true);
		long recFileSize = 0;
		
	    while((bytesRead=is.read(contents))!=-1){
	    			   	
	    	recFileSize += bytesRead; 
	    	//change the progressbar value
			progressbar.setValue((progress = (int)((recFileSize*100)/fileSize)));
			progressLabel.setText("File Recieved......." + progress + "%");		
			bos.write(contents, 0, bytesRead);
		}
		bos.flush();
		recFileMessFrame.setVisible(false);
		JOptionPane.showMessageDialog(null, "File recieved ! " + Paths.get(filePath).getFileName() );
		socket.close();
		ssock.close();
	} catch(Exception e) {
		System.out.println("[ReceiveFileThread] exception :: " + e);
		e.printStackTrace();
	}

	System.out.println("[ReceiveFileThread] :: File saved successfully!");
}
 
開發者ID:angeldove,項目名稱:LanChatLite,代碼行數:75,代碼來源:ReceiveFileThread.java


注:本文中的javax.swing.JProgressBar.setSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。