/** *FileChooserDemoConstructor
*/ public FileChooserDemo(SwingSet2 swingset) { // Set the title for this demo, and an icon used to represent this // demo inside the SwingSet2 app. super(swingset, "FileChooserDemo", "toolbar/JFileChooser.gif");
createFileChooserDemo();
}
// Create a panel to hold buttons
JPanel buttonPanel = new JPanel() { public Dimension getMaximumSize() {
return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
}
};
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
// Create a panel to hold the image
JPanel imagePanel = new JPanel();
imagePanel.setLayout(new BorderLayout());
imagePanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
JScrollPane scroller = new JScrollPane(theImage);
scroller.getVerticalScrollBar().setUnitIncrement(10);
scroller.getHorizontalScrollBar().setUnitIncrement(10);
imagePanel.add(scroller, BorderLayout.CENTER);
// add buttons and image panels to inner panel
innerPanel.add(buttonPanel);
innerPanel.add(Box.createRigidArea(HGAP30));
innerPanel.add(imagePanel);
innerPanel.add(Box.createRigidArea(HGAP20));
}
public JFileChooser createFileChooser() { // create a filechooser
JFileChooser fc = new JFileChooser(); if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) {
fc.setDragEnabled(true);
}
// set the current directory to be the images directory
File swingFile = new File("resources/images/About.jpg"); if(swingFile.exists()) {
fc.setCurrentDirectory(swingFile);
fc.setSelectedFile(swingFile);
}
return fc;
}
public JButton createPlainFileChooserButton() {
Action a = new AbstractAction(getString("FileChooserDemo.plainbutton")) { publicvoid actionPerformed(ActionEvent e) {
JFileChooser fc = createFileChooser();
// show the filechooser int result = fc.showOpenDialog(getDemoPanel());
// if we selected an image, load the image if(result == JFileChooser.APPROVE_OPTION) {
loadImage(fc.getSelectedFile().getPath());
}
}
};
return createButton(a);
}
public JButton createPreviewFileChooserButton() {
Action a = new AbstractAction(getString("FileChooserDemo.previewbutton")) { publicvoid actionPerformed(ActionEvent e) {
JFileChooser fc = createFileChooser();
// show the filechooser int result = fc.showOpenDialog(getDemoPanel());
// if we selected an image, load the image if(result == JFileChooser.APPROVE_OPTION) {
loadImage(fc.getSelectedFile().getPath());
}
}
};
return createButton(a);
}
private String createFileNameFilterDescriptionFromExtensions(
String description, String[] extensions) {
String fullDescription = (description == null) ? "(" : description + " ("; // build the description from the extension list
fullDescription += "." + extensions[0]; for (int i = 1; i < extensions.length; i++) {
fullDescription += ", .";
fullDescription += extensions[i];
}
fullDescription += ")";
return fullDescription;
}
public JButton createCustomFileChooserButton() {
Action a = new AbstractAction(getString("FileChooserDemo.custombutton")) { publicvoid actionPerformed(ActionEvent e) {
fc = createFileChooser();
public JButton createButton(Action a) {
JButton b = new JButton(a) { public Dimension getMaximumSize() { int width = Short.MAX_VALUE; int height = super.getMaximumSize().height;
return new Dimension(width, height);
}
};
return b;
}
public JButton createImageButton(Action a) {
JButton b = new JButton(a);
b.setMargin(new Insets(0,0,0,0));
return b;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.