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


Java FileDialog.setLocationRelativeTo方法代碼示例

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


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

示例1: showSaveDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
public static File showSaveDialog(Frame f,String title,String extension) {
	if(extension.startsWith("."))
		extension = extension.substring(1);
	
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter(extension));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);

	String s = fd.getFile();
	if(s==null)
		return null;
	
	if(s.toLowerCase().endsWith("."+extension)) {
		return new File(fd.getDirectory() + s);
	}
	
	return new File(fd.getDirectory() + fd.getFile()+"."+extension);
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:22,代碼來源:FileDialogUtils.java

示例2: doBrowseForFile

import java.awt.FileDialog; //導入方法依賴的package包/類
protected void doBrowseForFile(AudioPlayerComponent apc) {
	Window w = SwingUtilities.getWindowAncestor(apc);
	if(!(w instanceof Frame))
		throw new RuntimeException("cannot invoke a FileDialog if the player is not in a java.awt.Frame");
	//the button shouldn't be enabled if w isn't a Frame...
	Frame f = (Frame)w;
	FileDialog fd = new FileDialog(f);
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	
	if(fd.getFile()==null) throw new UserCancelledException();
	File file = new File(fd.getDirectory()+fd.getFile());
	try {
		apc.setSource( file.toURI().toURL() );
	} catch (MalformedURLException e) {
		e.printStackTrace();
		apc.setSource(null);
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:21,代碼來源:AudioPlayerUI.java

示例3: showSaveDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
protected File showSaveDialog() {
	FileDialog fd = new FileDialog(frame);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter("mov"));
	fd.setTitle("Save MOV File");
	fd.pack();
	fd.setLocationRelativeTo(frame);
	fd.setVisible(true);
	if(fd.getFile()==null)
		throw new UserCancelledException();
	String filepath = fd.getDirectory() + fd.getFile();
	if(!filepath.toLowerCase().endsWith(".mov")) {
		filepath += ".mov";
	}
	return new File(filepath);
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:17,代碼來源:ScreenCaptureDemo.java

示例4: browseForFile

import java.awt.FileDialog; //導入方法依賴的package包/類
/** If invoked from within a Frame: this pulls up a FileDialog to
 * browse for a file. If this is invoked from a secure applet: then
 * this will throw an exception.
 * 
 * @param ext an optional list of extensions
 * @return a File, or null if the user declined to select anything.
 */
public File browseForFile(String... ext) {
	Window w = SwingUtilities.getWindowAncestor(this);
	if(!(w instanceof Frame))
		throw new IllegalStateException();
	Frame frame = (Frame)w;
	FileDialog fd = new FileDialog(frame);
	if(ext!=null && ext.length>0 && (!(ext.length==1 && ext[0]==null)))
		fd.setFilenameFilter(new SuffixFilenameFilter(ext));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	String d = fd.getFile();
	if(d==null) return null;
	return new File(fd.getDirectory()+fd.getFile());
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:23,代碼來源:ImageQuantizationDemo.java

示例5: create

import java.awt.FileDialog; //導入方法依賴的package包/類
public static KeyStoreEditor create(Frame parentWindow) {
	KeyStoreEditor editor = new KeyStoreEditor();
	String dialogTitle = "Create Keystore";
	Icon icon = QDialog.getIcon(QDialog.PLAIN_MESSAGE);
	QDialog.showDialog(parentWindow, dialogTitle, icon, editor, editor.footer, true, null, null);
	JComponent button = editor.footer.getLastSelectedComponent();
	if( button==editor.footer.getButton(DialogFooter.OK_OPTION) ) {
		FileDialog fd = new FileDialog(parentWindow, "Create Keystore", FileDialog.SAVE);
		fd.setFilenameFilter(new SuffixFilenameFilter("jks"));
		fd.setFile("keystore.jks");
		fd.pack();
		fd.setLocationRelativeTo(null);
		fd.setVisible(true);
		if(fd.getFile()==null)
			return null;
		editor.jksFile = new File(fd.getDirectory()+fd.getFile());
		editor.create(false);
		return editor;
	} else {
		return null;
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:23,代碼來源:KeyStoreEditor.java

示例6: showOpenDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
public static File showOpenDialog(Frame f,String title,String... extensions) {
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.LOAD);
	if(extensions!=null && extensions.length>0)
		fd.setFilenameFilter(new SuffixFilenameFilter(extensions));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	if(fd.getFile()==null)
		return null;
	return new File(fd.getDirectory() + fd.getFile());
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:13,代碼來源:FileDialogUtils.java

示例7: doBrowse

import java.awt.FileDialog; //導入方法依賴的package包/類
/** Show a browse dialog, using the current file extensions if they are defined.
 * <p>In a JNLP session this uses a FileOpenService, but otherwise this
 * uses an AWT file dialog.
 *
 * @param component a component that relates to the Frame the possible dialog may be
 * anchored to. This can be any component that is showing.
 * @param extensions a list of possible extensions (or null if all files are accepted).
 * @return the FileData the user selected, or null if the user cancelled this
 * operation.
 */
public static FileData doBrowse(Component component,String[] extensions) {
	/*if(JVM.isJNLP()) {
		try {
			FileOpenService fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
			final FileContents contents = fos.openFileDialog(null, extensions);
			if(contents==null) return null;
			return new FileContentsWrapper(contents);
		} catch(Exception e) {
			e.printStackTrace();
		}
	}*/
	Window w = SwingUtilities.getWindowAncestor(component);
	if(w instanceof Frame) {
		Frame f = (Frame)w;
		FileDialog fd = new FileDialog(f);
		String[] ext = extensions;
		if(ext!=null && ext.length>0) {
			fd.setFilenameFilter(new SuffixFilenameFilter(ext));
		}
		fd.pack();
		fd.setLocationRelativeTo(null);
		fd.setVisible(true);
		
		if(fd.getFile()==null)
			return null;
		
		File file = new File(fd.getDirectory()+fd.getFile());
		return new FileWrapper(file);
	} else {
		throw new RuntimeException("window ancestor: "+w);
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:43,代碼來源:FilePanel.java

示例8: showFileDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
/** Show a FileDialog.
 * 
 * @param dialogMode must be FileDialog.LOAD or FileDialog.SAVE
 * @param dialogTitle the title of this dialog.
 * @param defaultFile an optional file to initially select.
 * @param documentFileExtension an optional extension to apply, or array of
 * extensions to accept.
 * This is used both as a file filter for this dialog and the zeroeth element is manually
 * appended to the filename if necessary during a save. It is OK to leave this null/empty for
 * an open dialog, but it is highly discouraged to leave this null for
 * a save dialog.
 * @return the File the user chose.
 * @throws UserCancelledException if the user cancelled this dialog.
 */
protected File showFileDialog(int dialogMode, String dialogTitle, File defaultFile,
		String... documentFileExtension) throws UserCancelledException {
	if(!(dialogMode==FileDialog.LOAD || dialogMode==FileDialog.SAVE))
		throw new IllegalArgumentException("dialogMode must be LOAD or SAVE");
	FileDialog fd = new FileDialog(frame, dialogTitle, dialogMode);
	SuffixFilenameFilter filter = null;
	if(documentFileExtension!=null && documentFileExtension.length>0) {
		filter = new SuffixFilenameFilter(documentFileExtension);
		fd.setFilenameFilter(filter);
	}
	if(defaultFile!=null) {
		fd.setFile(defaultFile.getAbsolutePath());
	}
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	if(fd.getFile()==null) throw new UserCancelledException();
	String s = fd.getFile();
	//this is going to cause problems on a sandboxed Mac:
	if(filter!=null && (!filter.accept( new File(fd.getDirectory(), s)))) {
		//TODO: if we change the file path (even a little), we need to
		//run a new (separate) check to see if the file exists and offer
		//a new do-you-want-to-replace dialog
		s = s+"."+documentFileExtension[0];
	}
	File file = new File(fd.getDirectory()+s);
	return file;
	
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:44,代碼來源:SaveControls.java


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