当前位置: 首页>>代码示例>>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;未经允许,请勿转载。