这是一个错误。
它在 JavaFX 2.2.6 和 Java 8(都还没有发布)中得到了修复:
RT-28571 在 DirectoryChooser 中选择 Windows 7 库会导致 COM 错误
该修复实际上不允许库选择。如果用户尝试选择一个库,JavaFX 系统会弹出一个警告并阻止目录选择器关闭:
我在 JavaFX 2.2.4(出现错误)和早期访问Java 8b77(显示警告消息)上运行的示例代码是:
import java.io.File;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
public class DirectoryChooserTest extends Application {
@Override public void start(final Stage stage) {
final TextField pathField = new TextField("C:/Users");
pathField.setPrefWidth(250);
Button chooseButton = new Button("Choose");
chooseButton.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent t) {
chooseDirectory(stage, pathField);
}
});
VBox layout = new VBox(10);
layout.getChildren().addAll(pathField, chooseButton);
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
stage.setScene(new Scene(layout));
stage.show();
}
private void chooseDirectory(Stage stage, TextField pathField) {
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("Selecione o diretório");
chooser.setInitialDirectory(new File(pathField.getText()));
File selectedDirectory = chooser.showDialog(stage);
if (selectedDirectory != null) {
pathField.setText(selectedDirectory.getAbsolutePath());
}
}
public static void main(String[] args) { launch(args); }
}
报告的错误是:
E r r o r : 8 0 0 7 0 0 5 7 i n p F i l e - > G e t D i s p l a y N a m e ( S I G D N _ F I L E S Y S P A T H , & p a t h )
C O M E r r o r : 8 0 0 7 0 0 5 7 T h e p a r a m e t e r i s i n c o r r e c t .
要获得错误,您需要从目录选择器对话框的左侧面板中选择一个库。