下面列出了javax.swing.JFileChooser#setPreferredSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void run() {
Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
JFileChooser fileopen = new JFileChooser();
fileopen.setFileFilter(new OpenFileFilter("bsh", "BSH files (*.bsh)"));
fileopen.setAcceptAllFileFilterUsed(false);
fileopen.setMultiSelectionEnabled(false);
fileopen.setPreferredSize(new Dimension(scr.width - 350, scr.height - 350));
if (fileopen.showOpenDialog(null) == 0) {
DebugMe.scriptFile = fileopen.getSelectedFile();
} else {
DebugMe.scriptFile = null;
}
dialogOpened.set(false);
}
/**
* initializes session file chooser, if not already done.
*/
private static void initSessionFc() {
sessionFc = new JFileChooser();
sessionFc.setMultiSelectionEnabled(true);
sessionFc.setCurrentDirectory(PrefManager.get().getSelectedPath());
if ((PrefManager.get().getPreferredSizeFileChooser().height > 0)) {
sessionFc.setPreferredSize(PrefManager.get().getPreferredSizeFileChooser());
}
sessionFc.setFileFilter(getSessionFilter());
sessionFc.setSelectedFile(null);
}
public OutDirWizardPage () {
super( PAGE_OUT_DIR, getDescription(), CPSWizardPage.WIZ_TYPE_PRE_INIT );
setLongDescription( getDescription() );
setPreferredSize( panelDim );
setMaximumSize( panelDim );
JLabel lblOutDir = new JLabel( "<html><body style='width: 300px'>" +
"<b>Select a folder or directory to store all of your crop planning data.</b>" +
"<p><p>If you have already used this program to create crop plans and would like to load that information, " +
"please select the folder or directory which contains your existing data. " +
"(The data files have names that start with \"CPSdb\".)" +
"" );
lblOutDir.setAlignmentX( Component.CENTER_ALIGNMENT );
String defaultDirectory = CPSGlobalSettings.getOutputDir();
flchOutDir = new JFileChooser();
flchOutDir.setSelectedFile( new File( defaultDirectory ) );
flchOutDir.setName( SETTING_OUT_DIR );
flchOutDir.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
flchOutDir.setMultiSelectionEnabled( false );
flchOutDir.setControlButtonsAreShown( false );
flchOutDir.addPropertyChangeListener( new PropertyChangeListener() {
public void propertyChange ( PropertyChangeEvent evt ) {
if ( evt.getPropertyName().equals( JFileChooser.SELECTED_FILE_CHANGED_PROPERTY ) ) {
outDirIsSelected = ( evt.getNewValue() != null ) ? true : false;
userInputReceived( flchOutDir, evt );
}
}
} ); // new PropChangeListener
flchOutDir.setPreferredSize( fileDim );
flchOutDir.setMaximumSize( fileDim );
add( lblOutDir );
add( flchOutDir );
}
public JFileChooser getExampleSessionChooser() throws MalformedURLException, JMSException, FileBrokerException, AuthCancelledException {
JFileChooser exampleSessionFileChooser = populateFileChooserFromServer(false);
exampleSessionFileChooser.setSelectedFile(new File("session"));
ServerFileUtils.hideJFileChooserButtons(exampleSessionFileChooser);
exampleSessionFileChooser.setPreferredSize(new Dimension(800, 600));
ServerFileSystemView view = (ServerFileSystemView) exampleSessionFileChooser.getFileSystemView();
exampleSessionFileChooser.setCurrentDirectory(view.getExampleSessionDir());
return exampleSessionFileChooser;
}
public JFileChooser getRemoteSessionChooser() throws MalformedURLException, JMSException, FileBrokerException, AuthCancelledException {
JFileChooser remoteSessionFileChooser = populateFileChooserFromServer();
remoteSessionFileChooser.setSelectedFile(new File("session"));
remoteSessionFileChooser.setPreferredSize(new Dimension(800, 600));
remoteSessionFileChooser.setAccessory(new RemoteSessionAccessory(remoteSessionFileChooser, app.getSessionManager(), app));
ServerFileUtils.hideJFileChooserButtons(remoteSessionFileChooser);
return remoteSessionFileChooser;
}
/** Shows dialog with the artifact chooser
* @return null if canceled selected jars if some jars selected
*/
static AntArtifactItem[] showDialog( String[] artifactTypes, Project master, Component parent ) {
JFileChooser chooser = ProjectChooser.projectChooser();
chooser.setDialogTitle( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_Title" ) ); // NOI18N
chooser.setApproveButtonText( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_SelectProject" ) ); // NOI18N
chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (AntArtifactChooser.class,"AD_AACH_SelectProject"));
AntArtifactChooser accessory = new AntArtifactChooser( artifactTypes, chooser );
chooser.setAccessory( accessory );
chooser.setPreferredSize( new Dimension( 650, 380 ) );
File defaultFolder = null;
FileObject defFo = master.getProjectDirectory();
if (defFo != null) {
defFo = defFo.getParent();
if (defFo != null) {
defaultFolder = FileUtil.toFile(defFo);
}
}
chooser.setCurrentDirectory (getLastUsedArtifactFolder(defaultFolder));
int option = chooser.showOpenDialog( parent ); // Show the chooser
if ( option == JFileChooser.APPROVE_OPTION ) {
File dir = chooser.getSelectedFile();
dir = FileUtil.normalizeFile (dir);
Project selectedProject = accessory.getProject( dir );
if ( selectedProject == null ) {
return null;
}
if ( selectedProject.getProjectDirectory().equals( master.getProjectDirectory() ) ) {
DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(
NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_RefToItself" ),
NotifyDescriptor.INFORMATION_MESSAGE ) );
return null;
}
if ( ProjectUtils.hasSubprojectCycles( master, selectedProject ) ) {
DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(
NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_Cycles" ),
NotifyDescriptor.INFORMATION_MESSAGE ) );
return null;
}
boolean noSuitableOutput = true;
for (String type : artifactTypes) {
if (AntArtifactQuery.findArtifactsByType(selectedProject, type).length > 0) {
noSuitableOutput = false;
break;
}
}
if (noSuitableOutput) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
NbBundle.getMessage (AntArtifactChooser.class,"MSG_NO_JAR_OUTPUT")));
return null;
}
setLastUsedArtifactFolder (FileUtil.normalizeFile(chooser.getCurrentDirectory()));
Object[] tmp = new Object[accessory.jListArtifacts.getModel().getSize()];
int count = 0;
for(int i = 0; i < tmp.length; i++) {
if (accessory.jListArtifacts.isSelectedIndex(i)) {
tmp[count] = accessory.jListArtifacts.getModel().getElementAt(i);
count++;
}
}
AntArtifactItem artifactItems[] = new AntArtifactItem[count];
System.arraycopy(tmp, 0, artifactItems, 0, count);
return artifactItems;
}
else {
return null;
}
}
private void setDialogSize(JFileChooser dialog) {
int width = guip.getBoardEditLoadWidth();
int height = guip.getBoardEditLoadHeight();
dialog.setPreferredSize(new Dimension(width, height));
}
public JFileChooser getManagementChooser() throws MalformedURLException, JMSException, FileBrokerException, AuthCancelledException {
JFileChooser sessionFileChooser = null;
// fetch current sessions to show in the dialog and create it
sessionFileChooser = populateFileChooserFromServer();
// tune GUI
sessionFileChooser.setDialogTitle("Manage");
sessionFileChooser.setPreferredSize(new Dimension(800, 600));
sessionFileChooser.setAccessory(new RemoteSessionAccessory(sessionFileChooser, app.getSessionManager(), app));
// hide buttons that we don't need
ServerFileUtils.hideJFileChooserButtons(sessionFileChooser);
ServerFileUtils.hideApproveButton(sessionFileChooser);
ServerFileUtils.setCancelButtonText(sessionFileChooser, "Close");
return sessionFileChooser;
}