下面列出了怎么用javafx.scene.control.RadioButton的API类实例代码及写法,或者点击链接到github查看源代码。
@Inject
public PreferenceOutputPane(@Named("smartRadio") PreferenceRadioButton smartRadio,
@Named("compressionEnabled") PreferenceCheckBox compressionEnabled) {
I18nContext i18n = DefaultI18nContext.getInstance();
ToggleGroup group = new ToggleGroup();
RadioButton manualRadio = new RadioButton(i18n.i18n("Manually selected"));
manualRadio.setToggleGroup(group);
manualRadio.getStyleClass().addAll(Style.VITEM.css());
manualRadio.setId("manualRadio");
smartRadio.getStyleClass().addAll(Style.VITEM.css());
smartRadio.setToggleGroup(group);
smartRadio.setGraphic(helpIcon(DefaultI18nContext.getInstance()
.i18n("Automatically set the destination directory to the selected PDF document directory")));
smartRadio.getStyleClass().addAll(Style.WITH_HELP.css());
if (isNull(group.getSelectedToggle())) {
group.selectToggle(manualRadio);
}
getChildren().addAll(manualRadio, smartRadio, compressionEnabled);
getStyleClass().addAll(Style.CONTAINER.css());
}
private VBox addFilter() {
filterText.setPromptText("Filter Node types");
final ToggleGroup toggleGroup = new ToggleGroup();
startsWithRb.setToggleGroup(toggleGroup);
startsWithRb.setPadding(new Insets(0, 0, 0, 5));
startsWithRb.setSelected(true);
final RadioButton containsRadioButton = new RadioButton("Contains");
containsRadioButton.setToggleGroup(toggleGroup);
containsRadioButton.setPadding(new Insets(0, 0, 0, 5));
toggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
populateTree();
});
filterText.textProperty().addListener((observable, oldValue, newValue) -> {
populateTree();
});
final HBox headerBox = new HBox(new Label("Filter: "), filterText, startsWithRb, containsRadioButton);
headerBox.setAlignment(Pos.CENTER_LEFT);
headerBox.setPadding(new Insets(5));
final VBox box = new VBox(schemaLabel, headerBox, treeView);
VBox.setVgrow(treeView, Priority.ALWAYS);
return box;
}
/**
* This method creates radio buttons and adds them to radioButtons
* and is used when the itemsProperty on the field changes.
*/
private void createRadioButtons() {
node.getChildren().clear();
radioButtons.clear();
for (int i = 0; i < field.getItems().size(); i++) {
RadioButton rb = new RadioButton();
rb.setText(field.getItems().get(i).toString());
rb.setToggleGroup(toggleGroup);
radioButtons.add(rb);
}
if (field.getSelection() != null) {
radioButtons.get(field.getItems().indexOf(field.getSelection())).setSelected(true);
}
node.getChildren().addAll(radioButtons);
}
public RadioButtons() {
super(400,100);
ToggleGroup tg = new ToggleGroup();
VBox vbox = new VBox();
vbox.setSpacing(5);
RadioButton rb1 = new RadioButton("Hello");
rb1.setToggleGroup(tg);
RadioButton rb2 = new RadioButton("Bye");
rb2.setToggleGroup(tg);
rb2.setSelected(true);
RadioButton rb3 = new RadioButton("Disabled");
rb3.setToggleGroup(tg);
rb3.setSelected(false);
rb3.setDisable(true);
vbox.getChildren().add(rb1);
vbox.getChildren().add(rb2);
vbox.getChildren().add(rb3);
getChildren().add(vbox);
}
private void checkType() {
try {
type = ConvolutionKernel.Convolution_Type.NONE;
grayCheck.setDisable(true);
RadioButton selected = (RadioButton) typeGroup.getSelectedToggle();
if (selected == null) {
return;
}
if (message("Blur").equals(selected.getText())) {
type = ConvolutionKernel.Convolution_Type.BLUR;
} else if (message("Sharpen").equals(selected.getText())) {
type = ConvolutionKernel.Convolution_Type.SHARPNEN;
} else if (message("Emboss").equals(selected.getText())) {
type = ConvolutionKernel.Convolution_Type.EMBOSS;
grayCheck.setDisable(false);
} else if (message("EdgeDetection").equals(selected.getText())) {
type = ConvolutionKernel.Convolution_Type.EDGE_DETECTION;
}
} catch (Exception e) {
logger.error(e.toString());
}
}
private void checkEdges() {
try {
if (isSettingValues) {
return;
}
edge_Op = ConvolutionKernel.Edge_Op.COPY;
RadioButton selected = (RadioButton) edgesGroup.getSelectedToggle();
if (selected == null) {
return;
}
if (!message("KeepValues").equals(selected.getText())) {
edge_Op = ConvolutionKernel.Edge_Op.FILL_ZERO;
}
} catch (Exception e) {
logger.error(e.toString());
}
}
private void checkReplaceType() {
RadioButton selected = (RadioButton) replaceGroup.getSelectedToggle();
if (message("ReplaceModified").equals(selected.getText())) {
replaceType = ReplaceType.ReplaceModified;
AppVariables.setUserConfigValue(FileArrangeExistedKey, "ReplaceModified");
} else if (message("NotCopy").equals(selected.getText())) {
replaceType = ReplaceType.NotCopy;
AppVariables.setUserConfigValue(FileArrangeExistedKey, "NotCopy");
} else if (message("Replace").equals(selected.getText())) {
replaceType = ReplaceType.Replace;
AppVariables.setUserConfigValue(FileArrangeExistedKey, "Replace");
} else if (message("Rename").equals(selected.getText())) {
replaceType = ReplaceType.Rename;
AppVariables.setUserConfigValue(FileArrangeExistedKey, "Rename");
} else {
replaceType = ReplaceType.ReplaceModified;
AppVariables.setUserConfigValue(FileArrangeExistedKey, "ReplaceModified");
}
}
private void checkFormat() {
jpegBox.setDisable(true);
jpegBox.setStyle(null);
thresholdInput.setDisable(true);
ditherCheck.setDisable(true);
RadioButton selected = (RadioButton) formatGroup.getSelectedToggle();
if (AppVariables.message("PNG").equals(selected.getText())) {
format = PdfImageFormat.Original;
} else if (AppVariables.message("CCITT4").equals(selected.getText())) {
format = PdfImageFormat.Tiff;
thresholdInput.setDisable(false);
ditherCheck.setDisable(false);
} else if (AppVariables.message("JpegQuailty").equals(selected.getText())) {
format = PdfImageFormat.Jpeg;
jpegBox.setDisable(false);
checkJpegQuality();
}
}
private void checkPageSize() {
standardSizeBox.setDisable(true);
standardDpiBox.setDisable(true);
customWidthInput.setDisable(true);
customHeightInput.setDisable(true);
customWidthInput.setStyle(null);
customHeightInput.setStyle(null);
isImageSize = false;
RadioButton selected = (RadioButton) sizeGroup.getSelectedToggle();
if (AppVariables.message("ImagesSize").equals(selected.getText())) {
isImageSize = true;
} else if (AppVariables.message("StandardSize").equals(selected.getText())) {
standardSizeBox.setDisable(false);
standardDpiBox.setDisable(false);
checkStandardValues();
} else if (AppVariables.message("Custom").equals(selected.getText())) {
customWidthInput.setDisable(false);
customHeightInput.setDisable(false);
checkCustomValues();
}
// AppVariables.setUserConfigValue(ImageCombineSizeKey, selected.getText());
}
protected void checkSevenCompress() {
String selected = ((RadioButton) sevenCompressGroup.getSelectedToggle()).getText();
switch (selected) {
case "LZMA2":
sevenCompress = SevenZMethod.LZMA2;
break;
case "COPY":
sevenCompress = SevenZMethod.COPY;
break;
case "DEFLATE":
sevenCompress = SevenZMethod.DEFLATE;
break;
case "BZIP2":
sevenCompress = SevenZMethod.BZIP2;
break;
}
}
private RadioButton createRadioButton(final Node rect, String name, final boolean toFront, ToggleGroup tg) {
final RadioButton radioButton = new RadioButton(name);
radioButton.setToggleGroup(tg);
radioButton.selectedProperty().addListener(new InvalidationListener() {
public void invalidated(Observable ov) {
if (radioButton.isSelected()) {
if (toFront) {
rect.toFront();
} else {
rect.toBack();
}
}
}
});
return radioButton;
}
private void checkPageSize() {
standardSizeBox.setDisable(true);
standardDpiBox.setDisable(true);
customWidthInput.setDisable(true);
customHeightInput.setDisable(true);
customWidthInput.setStyle(null);
customHeightInput.setStyle(null);
isImageSize = false;
RadioButton selected = (RadioButton) sizeGroup.getSelectedToggle();
if (AppVariables.message("ImagesSize").equals(selected.getText())) {
isImageSize = true;
} else if (AppVariables.message("StandardSize").equals(selected.getText())) {
standardSizeBox.setDisable(false);
standardDpiBox.setDisable(false);
checkStandardValues();
} else if (AppVariables.message("Custom").equals(selected.getText())) {
customWidthInput.setDisable(false);
customHeightInput.setDisable(false);
checkCustomValues();
}
// AppVariables.setUserConfigValue(ImageCombineSizeKey, selected.getText());
}
public void checkTargetExistType() {
if (isSettingValues) {
return;
}
if (targetAppendInput != null) {
targetAppendInput.setStyle(null);
}
RadioButton selected = (RadioButton) targetExistGroup.getSelectedToggle();
if (selected.equals(targetReplaceRadio)) {
targetExistType = TargetExistType.Replace;
} else if (selected.equals(targetRenameRadio)) {
targetExistType = TargetExistType.Rename;
if (targetAppendInput != null) {
if (targetAppendInput.getText() == null || targetAppendInput.getText().trim().isEmpty()) {
targetAppendInput.setStyle(badStyle);
} else {
setUserConfigValue("TargetExistAppend", targetAppendInput.getText().trim());
}
}
} else if (selected.equals(targetSkipRadio)) {
targetExistType = TargetExistType.Skip;
}
setUserConfigValue("TargetExistType", selected.getText());
}
private void checkInputType() {
try {
clear();
String selected = ((RadioButton) inputGroup.getSelectedToggle()).getText();
handleBox.getChildren().clear();
if (message("File").equals(selected)) {
handleBox.getChildren().addAll(fileBox, outputBox);
inputType = InputType.File;
} else {
handleBox.getChildren().addAll(inputArea, outputBox);
inputType = InputType.Input;
sourceFileInput.setStyle(null);
}
FxmlControl.refreshStyle(thisPane);
} catch (Exception e) {
logger.error(e.toString());
}
}
@Override
protected void setText ()
{
RadioButton selectedFileButton = (RadioButton) grpFileName.getSelectedToggle ();
if (selectedFileButton == null)
{
eraseCommand ();
return;
}
RadioButton selectedSpaceUnitsButton =
(RadioButton) grpSpaceUnits.getSelectedToggle ();
RadioButton selectedDispositionButton =
(RadioButton) grpDisposition.getSelectedToggle ();
tsoCommand.txtCommand
.setText (((TextField) selectedFileButton.getUserData ()).getText ());
setButton ();
}
private void checkAlgorithm() {
try {
clear();
String selected = ((RadioButton) algorithmGroup.getSelectedToggle()).getText();
switch (selected) {
case "SHA1":
algorithm = "SHA-1";
break;
case "SHA256":
algorithm = "SHA-256";
break;
default:
algorithm = "MD5";
break;
}
} catch (Exception e) {
logger.error(e.toString());
}
}
public void checkPrimaries() {
try {
RadioButton selected = (RadioButton) pGroup.getSelectedToggle();
if (message("ColorSpace").equals(selected.getText())) {
primariesBox.setDisable(true);
whiteVBox.setDisable(true);
checkColorSpace();
} else if (message("InputPrimaries").equals(selected.getText())) {
colorSpaceName = null;
primariesBox.setDisable(false);
whiteVBox.setDisable(false);
checkRGBInputs();
checkWhite();
}
} catch (Exception e) {
checkRGBInputs();
}
}
public void checkWhite() {
if (isSettingValues) {
return;
}
try {
RadioButton selected = (RadioButton) wGroup.getSelectedToggle();
if (message("StandardIlluminant").equals(selected.getText())) {
whiteHBox.setDisable(true);
checkIlluminant();
} else if (message("InputWhitePoint").equals(selected.getText())) {
currentWhiteName = null;
whiteHBox.setDisable(false);
checkWhiteInputs();
}
} catch (Exception e) {
checkWhiteInputs();
}
}
private void checkFormat() {
jpegBox.setDisable(true);
jpegBox.setStyle(null);
thresholdInput.setDisable(true);
RadioButton selected = (RadioButton) imageTypeGroup.getSelectedToggle();
if (AppVariables.message("PNG").equals(selected.getText())) {
imageType = ImageType.PNG;
} else if (AppVariables.message("CCITT4").equals(selected.getText())) {
imageType = ImageType.TIFF;
thresholdInput.setDisable(false);
} else if (AppVariables.message("JpegQuailty").equals(selected.getText())) {
imageType = ImageType.JPG;
jpegBox.setDisable(false);
checkJpegQuality();
}
}
private void checkSplitType() {
filesNumberInput.setDisable(true);
bytesNumberInput.setDisable(true);
listInput.setDisable(true);
filesNumberInput.setStyle(null);
bytesNumberInput.setStyle(null);
listInput.setStyle(null);
RadioButton selected = (RadioButton) splitGroup.getSelectedToggle();
if (AppVariables.message("SplitByFilesNumber").equals(selected.getText())) {
splitType = FileSplitType.FilesNumber;
filesNumberInput.setDisable(false);
checkFilesNumber();
} else if (AppVariables.message("SplitByBytesNumber").equals(selected.getText())) {
splitType = FileSplitType.BytesNumber;
bytesNumberInput.setDisable(false);
checkBytesNumber();
} else if (AppVariables.message("CutByStartEndByteList").equals(selected.getText())) {
splitType = FileSplitType.StartEndList;
listInput.setDisable(false);
checkStartEndList();
}
}
public void addRow(RadioButton radio, Region field, Text helpIcon) {
requireNotNullArg(radio, "Cannot add a null radio");
requireNotNullArg(field, "Cannot add a null field");
GridPane.setValignment(radio, VPos.BOTTOM);
GridPane.setValignment(field, VPos.BOTTOM);
GridPane.setHalignment(radio, HPos.LEFT);
GridPane.setHalignment(field, HPos.LEFT);
GridPane.setFillWidth(field, true);
field.setPrefWidth(300);
field.setDisable(true);
radio.selectedProperty().addListener((o, oldVal, newVal) -> {
field.setDisable(!newVal);
if (newVal) {
field.requestFocus();
}
});
radio.setToggleGroup(group);
add(radio, 0, rows);
add(field, 1, rows);
if (nonNull(helpIcon)) {
add(helpIcon, 2, rows);
}
rows++;
}
@Test
public void getText() {
RadioButton radioButton = (RadioButton) getPrimaryStage().getScene().getRoot().lookup(".radio-button");
LoggingRecorder lr = new LoggingRecorder();
List<String> text = new ArrayList<>();
Platform.runLater(new Runnable() {
@Override
public void run() {
RFXToggleButton rfxToggleButton = new RFXToggleButton(radioButton, null, null, lr);
radioButton.setSelected(false);
rfxToggleButton.mouseEntered(null);
radioButton.setSelected(true);
rfxToggleButton.mouseClicked(null);
text.add(rfxToggleButton._getText());
}
});
new Wait("Waiting for toggle button text") {
@Override
public boolean until() {
return text.size() > 0;
}
};
AssertJUnit.assertEquals("Hello", text.get(0));
}
private void checkLocation() {
if (foreImage == null || backImage == null) {
return;
}
isSettingValues = true;
RadioButton selected = (RadioButton) locationGroup.getSelectedToggle();
if (AppVariables.message("FinB").equals(selected.getText())) {
location = ImagesRelativeLocation.Foreground_In_Background;
pointLabel.setText(AppVariables.message("ClickOnBackgournd"));
bottomLabel.setText(AppVariables.message("BlendedSize") + ": "
+ (int) backImage.getWidth() + "*" + (int) backImage.getHeight());
} else if (AppVariables.message("BinF").equals(selected.getText())) {
location = ImagesRelativeLocation.Background_In_Foreground;
pointLabel.setText(AppVariables.message("ClickOnForegournd"));
bottomLabel.setText(AppVariables.message("BlendedSize") + ": "
+ (int) foreImage.getWidth() + "*" + (int) foreImage.getHeight());
} else {
return;
}
pointX.setText("0");
pointY.setText("0");
isSettingValues = false;
checkPoint();
}
public void checkAlgorithm() {
try {
RadioButton selected = (RadioButton) algorithmGroup.getSelectedToggle();
switch (selected.getText()) {
case "Bradford":
algorithm = ChromaticAdaptation.ChromaticAdaptationAlgorithm.Bradford;
break;
case "XYZ Scaling":
algorithm = ChromaticAdaptation.ChromaticAdaptationAlgorithm.XYZScaling;
break;
case "Von Kries":
algorithm = ChromaticAdaptation.ChromaticAdaptationAlgorithm.VonKries;
break;
default:
algorithm = ChromaticAdaptation.ChromaticAdaptationAlgorithm.Bradford;
}
} catch (Exception e) {
algorithm = ChromaticAdaptation.ChromaticAdaptationAlgorithm.Bradford;
}
}
private void loadTableData() {
try {
tableBox.getChildren().clear();
RadioButton selected = (RadioButton) dataGroup.getSelectedToggle();
if (message("Calculate").equals(selected.getText())) {
tableBox.getChildren().addAll(dataToolbar, calculateBox);
} else if (message("Input").equals(selected.getText())) {
tableBox.getChildren().addAll(dataToolbar, inputBox);
}
FxmlControl.refreshStyle(tableBox);
} catch (Exception e) {
logger.error(e.toString());
}
}
private RadioButton createRadioButton(final Node rect, String name, final boolean toFront, ToggleGroup tg) {
final RadioButton radioButton = new RadioButton(name);
radioButton.setToggleGroup(tg);
radioButton.selectedProperty().addListener(new InvalidationListener() {
public void invalidated(Observable ov) {
if (radioButton.isSelected()) {
if (toFront) {
rect.toFront();
} else {
rect.toBack();
}
}
}
});
return radioButton;
}
@Override
public void setContent(final Tab tab) {
GraphManager.getDefault().addGraphManagerListener(this);
newActiveGraph(GraphManager.getDefault().getActiveGraph());
final TextField filterText = new TextField();
filterText.setPromptText("Filter attribute names");
final ToggleGroup tg = new ToggleGroup();
final RadioButton startsWithRb = new RadioButton("Starts with");
startsWithRb.setToggleGroup(tg);
startsWithRb.setPadding(new Insets(0, 0, 0, 5));
startsWithRb.setSelected(true);
final RadioButton containsRb = new RadioButton("Contains");
containsRb.setToggleGroup(tg);
containsRb.setPadding(new Insets(0, 0, 0, 5));
tg.selectedToggleProperty().addListener((ov, oldValue, newValue) -> {
filter(table, filterText.getText(), startsWithRb.isSelected());
});
filterText.textProperty().addListener((ov, oldValue, newValue) -> {
filter(table, newValue, startsWithRb.isSelected());
});
final HBox headerBox = new HBox(new Label("Filter: "), filterText, startsWithRb, containsRb);
headerBox.setAlignment(Pos.CENTER_LEFT);
headerBox.setPadding(new Insets(5));
final VBox box = new VBox(schemaLabel, headerBox, table);
VBox.setVgrow(table, Priority.ALWAYS);
Platform.runLater(() -> {
tab.setContent(box);
});
}
public TransactionTypeNodeProvider() {
schemaLabel = new Label(SeparatorConstants.HYPHEN);
schemaLabel.setPadding(new Insets(5));
treeView = new TreeView<>();
transactionTypes = new ArrayList<>();
detailsView = new HBox();
detailsView.setPadding(new Insets(5));
startsWithRb = new RadioButton("Starts with");
filterText = new TextField();
setCellFactory();
}
private void smash(){
statusLbl.setText("");
if (MediatorControl.getInstance().getTransferActive()) {
ServiceWindow.getErrorNotification(rb.getString("windowTitleError"), rb.getString("windowBodyPleaseFinishTransfersFirst"));
return;
}
Task<Boolean> RcmTask;
RadioButton selectedRadio = (RadioButton)rcmToggleGrp.getSelectedToggle();
switch (selectedRadio.getId()){
case "pldrRadio1":
RcmTask = new RcmTask(payloadFPathLbl1.getText());
break;
case "pldrRadio2":
RcmTask = new RcmTask(payloadFPathLbl2.getText());
break;
case "pldrRadio3":
RcmTask = new RcmTask(payloadFPathLbl3.getText());
break;
case "pldrRadio4":
RcmTask = new RcmTask(payloadFPathLbl4.getText());
break;
case "pldrRadio5":
RcmTask = new RcmTask(payloadFPathLbl5.getText());
break;
default:
return;
}
RcmTask.setOnSucceeded(event -> {
if (RcmTask.getValue())
statusLbl.setText(rb.getString("done_txt"));
else
statusLbl.setText(rb.getString("failure_txt"));
});
Thread RcmThread = new Thread(RcmTask);
RcmThread.setDaemon(true);
RcmThread.start();
}
/**
* Create the panel of radio buttons.
* @return pane with radio buttons
*/
private Pane buildButtonPanel()
{
ListFacade<InfoFacade> availableList = chooser.getAvailableList();
int count = 0;
avaRadioButton = new RadioButton[availableList.getSize()];
// Create the buttons
for (InfoFacade infoFacade : availableList)
{
avaRadioButton[count] = new RadioButton(infoFacade.toString());
avaRadioButton[count].setToggleGroup(toggleGroup);
avaRadioButton[count].setUserData(count);
++count;
}
if (count > 0)
{
avaRadioButton[0].setSelected(true);
}
if (count > 10)
{
return buildTwoColLayout();
}
return buildNormalColLayout();
}