下面列出了javax.swing.JRadioButton#addActionListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void addBottomFilter() {
rtBut = new JRadioButton("RT");
bottomPanel.add(rtBut);
rtBut.addActionListener(this);
maxBut = new JRadioButton("MAX");
bottomPanel.add(maxBut);
maxBut.addActionListener(this);
minBut = new JRadioButton("MIN");
bottomPanel.add(minBut);
minBut.addActionListener(this);
ButtonGroup group = new ButtonGroup();
group.add(rtBut);
group.add(maxBut);
group.add(minBut);
healthTableToDisplay = Config.loadGraphIntValue(fox.getIdString(), GraphFrame.SAVED_PLOT, FoxFramePart.TYPE_REAL_TIME, HEALTHTAB, "healthTableToDisplay");
if (healthTableToDisplay == DISPLAY_RT) {
rtBut.setSelected(true);
} else if (healthTableToDisplay == DISPLAY_MAX) {
maxBut.setSelected(true);
} else {
minBut.setSelected(true);
}
super.addBottomFilter();
}
/** Create a bank of radio buttons. A radio button provides a list of
* choices, only one of which may be chosen at a time.
* @param name The name used to identify the entry (when calling get).
* @param label The label to attach to the entry.
* @param values The list of possible choices.
* @param defaultValue Default value.
*/
public void addRadioButtons(
String name,
String label,
String[] values,
String defaultValue) {
JLabel lbl = new JLabel(label + ": ");
lbl.setBackground(_background);
FlowLayout flow = new FlowLayout();
flow.setAlignment(FlowLayout.LEFT);
// This must be a JPanel, not a Panel, or the scroll bars won't work.
JPanel buttonPanel = new JPanel(flow);
ButtonGroup group = new ButtonGroup();
QueryActionListener listener = new QueryActionListener(name);
// Regrettably, ButtonGroup provides no method to find out
// which button is selected, so we have to go through a
// song and dance here...
JRadioButton[] buttons = new JRadioButton[values.length];
for (int i = 0; i < values.length; i++) {
JRadioButton checkbox = new JRadioButton(values[i]);
buttons[i] = checkbox;
checkbox.setBackground(_background);
// The following (essentially) undocumented method does nothing...
// checkbox.setContentAreaFilled(true);
checkbox.setOpaque(false);
if (values[i].equals(defaultValue)) {
checkbox.setSelected(true);
}
group.add(checkbox);
buttonPanel.add(checkbox);
// Add the listener last so that there is no notification
// of the first value.
checkbox.addActionListener(listener);
}
_addPair(name, lbl, buttonPanel, buttons);
}
private JRadioButton addRadioButton(String name, JPanel panel) {
JRadioButton radioButton = new JRadioButton(name);
radioButton.setEnabled(true);
radioButton.addActionListener(this);
panel.add(radioButton);
return radioButton;
}
private JRadioButton createDoubleClickRadioButton(String title,
final int action) {
JRadioButton node = new JRadioButton(title);
node.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setDoubleClick(action);
}
});
return node;
}
private JRadioButton createSingleClickRadioButton(String title,
final int action) {
JRadioButton node = new JRadioButton(title);
node.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSingleClick(action);
}
});
return node;
}
private void createButtonsAndLabels() {
copyAllRButton = new JRadioButton("Copy");
geocodingRButton = new JRadioButton("Use Geocoding Only");
subsetRButton = new JRadioButton("Use Subset");
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(copyAllRButton);
buttonGroup.add(geocodingRButton);
buttonGroup.add(subsetRButton);
copyAllRButton.setActionCommand(COPY_ALL_COMMAND);
geocodingRButton.setActionCommand(COPY_GEOCODING_COMMAND);
subsetRButton.setActionCommand(COPY_SUBSET_COMMAND);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateUI();
}
};
copyAllRButton.addActionListener(listener);
geocodingRButton.addActionListener(listener);
subsetRButton.addActionListener(listener);
if (subsetDef != null) {
subsetRButton.setSelected(true);
} else {
geocodingRButton.setSelected(true);
}
subsetButton = new JButton("Subset...");
subsetButton.addActionListener(createSubsetButtonListener());
labelWidthInfo = new JLabel(DEFAULT_NUMBER_TEXT);
labelHeightInfo = new JLabel(DEFAULT_NUMBER_TEXT);
labelCenterLatInfo = new JLabel(DEFAULT_LATLON_TEXT);
labelCenterLonInfo = new JLabel(DEFAULT_LATLON_TEXT);
}
private JRadioButton createLocalityRadioButton(String title,
final int action) {
JRadioButton node = new JRadioButton(title);
node.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setLocalityAlgorithm(action);
}
});
return node;
}
private void addOscillator(final UnitOscillator osc, String label) {
oscillators.add(osc);
synth.add(osc);
freqRamp.output.connect(osc.frequency);
if (osc instanceof PulseOscillatorBL) {
widthRamp.output.connect(((PulseOscillatorBL)osc).width);
}
if (osc instanceof PulseOscillator) {
widthRamp.output.connect(((PulseOscillator)osc).width);
}
if (osc instanceof MorphingOscillatorBL) {
shapeRamp.output.connect(((MorphingOscillatorBL)osc).shape);
}
osc.amplitude.set(1.0);
JRadioButton checkBox = new JRadioButton(label);
buttonGroup.add(checkBox);
checkBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// Disconnect other oscillators.
oscGain.inputA.disconnectAll(0);
// Connect this one.
osc.output.connect(oscGain.inputA);
widthSlider.setEnabled(osc instanceof PulseOscillator
|| osc instanceof PulseOscillatorBL);
shapeSlider.setEnabled(osc instanceof MorphingOscillatorBL);
}
});
oscPanel.add(checkBox);
}
public RadioColumnEditor() {
super();
theRadioButton = new JRadioButton();
theRadioButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
fireEditingStopped();
}
});
}
public ChartTableToggle(NMONVisualizerGui gui) {
// border layout pads differently than the default flow layout
// use it so the text for the radio buttons lines up with other text in the parent
super(new BorderLayout());
this.gui = gui;
charts = new JRadioButton("Charts");
table = new JRadioButton("Table");
charts.setFont(Styles.LABEL);
table.setFont(Styles.LABEL);
charts.setBorder(Styles.CONTENT_BORDER);
table.setBorder(Styles.CONTENT_BORDER);
charts.setActionCommand("Charts");
table.setActionCommand("Table");
ActionListener toggle = new ActionListener() {
public void actionPerformed(ActionEvent e) {
ChartTableToggle.this.gui.setProperty("chartsDisplayed", !e.getActionCommand().equals("Table"));
}
};
charts.addActionListener(toggle);
table.addActionListener(toggle);
ButtonGroup group = new ButtonGroup();
group.add(charts);
group.add(table);
charts.setSelected(true);
table.setSelected(false);
add(charts, BorderLayout.LINE_START);
add(table, BorderLayout.LINE_END);
gui.addPropertyChangeListener("chartsDisplayed", this);
}
@Override
protected JRadioButton createRadioButton() {
final JRadioButton button = super.createRadioButton();
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean collocate = button.isSelected();
getCrsUI().firePropertyChange("collocate", !collocate, collocate);
}
});
return button;
}
protected void configureFileChooser(final SnapFileChooser fileChooser, final ProductSceneView view,
String imageBaseName) {
fileChooser.setDialogTitle(SnapApp.getDefault().getInstanceName() + " - " + "Export Image"); /*I18N*/
if (view.isRGB()) {
fileChooser.setCurrentFilename(imageBaseName + "_RGB");
} else {
fileChooser.setCurrentFilename(imageBaseName + "_" + view.getRaster().getName());
}
final JPanel regionPanel = new JPanel(new GridLayout(2, 1));
regionPanel.setBorder(BorderFactory.createTitledBorder("Image Region"));
buttonFullRegion = new JRadioButton("Full scene");
buttonFullRegion.setToolTipText("Use the image boundaries of the source data");
buttonFullRegion.setActionCommand(AC_FULL_REGION);
buttonVisibleRegion = new JRadioButton("View region");
buttonVisibleRegion.setToolTipText("Use the image boundaries of the view window");
buttonVisibleRegion.setActionCommand(AC_VIEW_REGION);
regionPanel.add(buttonVisibleRegion);
regionPanel.add(buttonFullRegion);
buttonGroupRegion = new ButtonGroup();
buttonGroupRegion.add(buttonVisibleRegion);
buttonGroupRegion.add(buttonFullRegion);
final JPanel resolutionPanel = new JPanel(new GridLayout(3, 1));
resolutionPanel.setBorder(BorderFactory.createTitledBorder("Image Resolution"));
buttonViewResolution = new JRadioButton("View resolution");
buttonViewResolution.setToolTipText("Use the resolution of the view window as it is on the computer screen");
buttonViewResolution.setActionCommand(AC_VIEW_RES);
buttonFullResolution = new JRadioButton("Full resolution");
buttonFullResolution.setToolTipText("Use the resolution of the source data");
buttonFullResolution.setActionCommand(AC_FULL_RES);
buttonUserResolution = new JRadioButton("User resolution");
buttonUserResolution.setToolTipText("Use a custom resolution set by the user");
buttonUserResolution.setActionCommand(AC_USER_RES);
resolutionPanel.add(buttonViewResolution);
resolutionPanel.add(buttonFullResolution);
resolutionPanel.add(buttonUserResolution);
buttonGroupResolution = new ButtonGroup();
buttonGroupResolution.add(buttonViewResolution);
buttonGroupResolution.add(buttonFullResolution);
buttonGroupResolution.add(buttonUserResolution);
sizeComponent = new SizeComponent(view);
JComponent sizePanel = sizeComponent.createComponent();
sizePanel.setBorder(BorderFactory.createTitledBorder("Image Dimension")); /*I18N*/
sizePanel.setToolTipText("Fixed ratio is automatically applied to width and height");
final JPanel accessory = new JPanel();
accessory.setLayout(new BoxLayout(accessory, BoxLayout.Y_AXIS));
accessory.add(regionPanel);
accessory.add(resolutionPanel);
accessory.add(sizePanel);
fileChooser.setAccessory(accessory);
buttonVisibleRegion.addActionListener(e -> updateComponents(e.getActionCommand()));
buttonFullRegion.addActionListener(e -> updateComponents(e.getActionCommand()));
buttonViewResolution.addActionListener(e -> updateComponents(e.getActionCommand()));
buttonFullResolution.addActionListener(e -> updateComponents(e.getActionCommand()));
buttonUserResolution.addActionListener(e -> updateComponents(e.getActionCommand()));
updateComponents(PSEUDO_AC_INIT);
}
/**
* Create a bank of radio buttons. A radio button provides a list of
* choices, only one of which may be chosen at a time.
*
* @param name
* The name used to identify the entry (when calling get).
* @param label
* The label to attach to the entry.
* @param values
* The list of possible choices.
* @param defaultValue
* Default value.
*/
public void addRadioButtons(String name, String label, String[] values, String defaultValue) {
JLabel lbl = new JLabel(label + ": ");
lbl.setBackground(_background);
FlowLayout flow = new FlowLayout();
flow.setAlignment(FlowLayout.LEFT);
// This must be a JPanel, not a Panel, or the scroll bars won't work.
JPanel buttonPanel = new JPanel(flow);
ButtonGroup group = new ButtonGroup();
QueryActionListener listener = new QueryActionListener(name);
// Regrettably, ButtonGroup provides no method to find out
// which button is selected, so we have to go through a
// song and dance here...
JRadioButton[] buttons = new JRadioButton[values.length];
for (int i = 0; i < values.length; i++) {
JRadioButton checkbox = new JRadioButton(values[i]);
buttons[i] = checkbox;
checkbox.setBackground(_background);
// The following (essentially) undocumented method does nothing...
// checkbox.setContentAreaFilled(true);
checkbox.setOpaque(false);
if (values[i].equals(defaultValue)) {
checkbox.setSelected(true);
}
group.add(checkbox);
buttonPanel.add(checkbox);
// Add the listener last so that there is no notification
// of the first value.
checkbox.addActionListener(listener);
}
_addPair(name, lbl, buttonPanel, buttons);
}
/**
* This is the control panel of the Verifier GUI
*/
private void createControlPanel() {
allButton = new JRadioButton();
org.openide.awt.Mnemonics.setLocalizedText(allButton, allString); // NOI18N
failButton = new JRadioButton();
org.openide.awt.Mnemonics.setLocalizedText(failButton, failString); // NOI18N
warnButton = new JRadioButton();
org.openide.awt.Mnemonics.setLocalizedText(warnButton, warnString); // NOI18N
controlPanel = new JPanel();
// 508 for this panel
controlPanel.getAccessibleContext().setAccessibleName(panelName);
controlPanel.getAccessibleContext().setAccessibleDescription(panelDesc);
allButton.getAccessibleContext().setAccessibleName(radioButtonName);
allButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
failButton.getAccessibleContext().setAccessibleName(radioButtonName);
failButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
warnButton.getAccessibleContext().setAccessibleName(radioButtonName);
warnButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
// set-up the radio buttons.
allButton.setActionCommand(allString);
allButton.setSelected(true);
failButton.setActionCommand(failString);
warnButton.setActionCommand(warnString);
// Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(allButton);
group.add(failButton);
group.add(warnButton);
// Put the radio buttons in a column in a panel
JPanel radioPanel = new JPanel();
// 508 for this panel
radioPanel.getAccessibleContext().setAccessibleName(panelName);
radioPanel.getAccessibleContext().setAccessibleDescription(panelDesc);
radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.X_AXIS));
JLabel d = new JLabel(
NbBundle.getMessage(VerifierSupport.class,"DisplayLabel")); // NOI18N
d.setVerticalAlignment(SwingConstants.BOTTOM);
// 508 compliance for the JLabel
d.getAccessibleContext().setAccessibleName(
NbBundle.getMessage(VerifierSupport.class,"Label")); // NOI18N
d.getAccessibleContext().setAccessibleDescription(
NbBundle.getMessage(VerifierSupport.class,"This_is_a_label")); // NOI18N
radioPanel.add(d);
radioPanel.add(allButton);
radioPanel.add(failButton);
radioPanel.add(warnButton);
// Add the controls to the Panel
controlPanel.add(radioPanel);
// Register a listener for the report level radio buttons.
myListener = new RadioListener();
allButton.addActionListener(myListener);
failButton.addActionListener(myListener);
warnButton.addActionListener(myListener);
}
/**
* Creates panel for delimeter selection.
* This panel is used on the first step
*
* @return JPanel delimeter selection panel
*/
private JPanel createDelimSelectorPanel() {
JXTaskPane delimPanel = createTaskPane();
delimPanel.setLayout(new GridBagLayout());
delimRadioButtons = new ArrayList<JRadioButton>();
Map<String, JRadioButton>delimRadioButtonsByDelims = new HashMap<String, JRadioButton>();
ButtonGroup delimGroup = new ButtonGroup();
String[] selectorLabels = new String[Delimiter.values().length];
String[] delimiters = new String[Delimiter.values().length];
for(int i = 0; i < Delimiter.values().length; i++){
selectorLabels[i] = Delimiter.values()[i].getName();
delimiters[i] = Delimiter.values()[i].toString();
}
for (int i = 0; i < selectorLabels.length; i++) {
JRadioButton selector = new JRadioButton(selectorLabels[i]);
selector.setActionCommand(delimiters[i]);
selector.addActionListener(this);
selector.setOpaque(false);
delimGroup.add(selector);
delimRadioButtons.add(selector);
delimRadioButtonsByDelims.put(delimiters[i], selector);
}
customDelimRadioButton = new JRadioButton("Other:");
customDelimRadioButton.addActionListener(this);
customDelimRadioButton.setOpaque(false);
delimGroup.add(customDelimRadioButton);
delimRadioButtons.add(customDelimRadioButton);
delimRadioButtons.get(0).setSelected(true);
customDelimField = new JTextField(3);
customDelimField.addCaretListener(this);
//customDelimField.setPreferredSize(new Dimension(25, 20));
customDelimField.setMargin(new Insets(2, 2, 2, 2));
useCustomDelimButton = new JButton("Use");
useCustomDelimButton.addActionListener(this);
useCustomDelimButton.setEnabled(false);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0; c.gridy = 0;
c.gridwidth = 2;
c.anchor = GridBagConstraints.WEST;
c.weightx = 1.0;
c.fill = GridBagConstraints.HORIZONTAL;
for (int i = 0; i < delimRadioButtons.size()-1; i++) {
delimPanel.add(delimRadioButtons.get(i), c);
c.gridy++;
}
c.gridx = 0;
c.gridwidth = 1;
c.weightx = 0.0;
c.fill = GridBagConstraints.NONE;
delimPanel.add(customDelimRadioButton, c);
c.gridx = 1;
delimPanel.add(customDelimField, c);
c.gridx++;
delimPanel.add(useCustomDelimButton, c);
delimPanel.setTitle("Column Delimiter");
return delimPanel;
}
private void addTestingType(final int type, JRadioButton button) {
testingType2RadioButton[type] = button;
button.addActionListener(e -> updateLabelComponents(type));
}
private void initGui() {
impAppRadioNoImp = new JRadioButton();
impAppRadioAppImp = new JRadioButton();
impAppRadioImp = new JRadioButton();
ButtonGroup impAppRadio = new ButtonGroup();
impAppRadio.add(impAppRadioNoImp);
impAppRadio.add(impAppRadioImp);
impAppRadio.add(impAppRadioAppImp);
impAppOldLabel = new JLabel();
impAppOldText = new JTextField();
PopupMenuDecorator.getInstance().decorate(impAppOldText);
setLayout(new GridBagLayout());
{
block1 = new JPanel();
add(block1, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,5,0,5,0));
block1.setBorder(BorderFactory.createTitledBorder(""));
block1.setLayout(new GridBagLayout());
impAppRadioImp.setIconTextGap(10);
impAppRadioAppImp.setIconTextGap(10);
impAppRadioNoImp.setIconTextGap(10);
{
block1.add(impAppRadioImp, GuiUtil.setConstraints(0,0,1.0,1.0,GridBagConstraints.BOTH,0,5,0,5));
block1.add(impAppRadioAppImp, GuiUtil.setConstraints(0,1,1.0,1.0,GridBagConstraints.BOTH,0,5,0,5));
block1.add(impAppRadioNoImp, GuiUtil.setConstraints(0,2,1.0,1.0,GridBagConstraints.BOTH,0,5,0,5));
}
block2 = new JPanel();
add(block2, GuiUtil.setConstraints(0,1,1.0,0.0,GridBagConstraints.BOTH,5,0,5,0));
block2.setBorder(BorderFactory.createTitledBorder(""));
block2.setLayout(new GridBagLayout());
{
Box themeBox = Box.createHorizontalBox();
themeBox.add(impAppOldLabel);
themeBox.add(Box.createRigidArea(new Dimension(10, 0)));
themeBox.add(impAppOldText);
block2.add(themeBox, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,5,5,0,5));
}
}
ActionListener themeListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
setEnabledTheme();
}
};
impAppRadioNoImp.addActionListener(themeListener);
impAppRadioAppImp.addActionListener(themeListener);
impAppRadioImp.addActionListener(themeListener);
}
private JRadioButton radioButtonForFitFunctionFactory(//
final DataModelFitFunctionInterface rawRatioDataModel, final FitFunctionTypeEnum fitFunctionType) {
// feb 2013
String overDispersion = "";
DecimalFormat f = new DecimalFormat("0.000");
if (fitFunctionType.compareTo(FitFunctionTypeEnum.MEAN_DH) == 0) {
if (((RawRatioDataModel)rawRatioDataModel).isOverDispersionSelectedDownHole()&& rawRatioDataModel.doesFitFunctionTypeHaveOD(fitFunctionType)) {
overDispersion = "-OD \u03BE = " + f.format(rawRatioDataModel.getXIforFitFunction(fitFunctionType));
}
} else {
if (rawRatioDataModel.isOverDispersionSelected() && rawRatioDataModel.doesFitFunctionTypeHaveOD(fitFunctionType)) {
if (fitFunctionType.compareTo(FitFunctionTypeEnum.SMOOTHING_SPLINE) == 0) {
overDispersion = "-OD";
} else {
overDispersion = "-OD \u03BE = " + f.format(rawRatioDataModel.getXIforFitFunction(fitFunctionType));
}
}
}
JRadioButton functionChoiceRadioButton = new JRadioButton(fitFunctionType.getPrettyName() + overDispersion);
functionChoiceRadioButton.setName(fitFunctionType.getName());
functionChoiceRadioButton.setFont(ReduxConstants.sansSerif_10_Plain);// new Font("SansSerif", Font.PLAIN, 10));
functionChoiceRadioButton.setBounds(1, 1, 160, 17);
functionChoiceRadioButton.setOpaque(false);
if (fitFunctionType.compareTo(FitFunctionTypeEnum.MEAN_DH) == 0) {
// only one available for downhole
functionChoiceRadioButton.setSelected(true);
} else {
functionChoiceRadioButton.setSelected( //
rawRatioDataModel.getSelectedFitFunctionType().compareTo(fitFunctionType) == 0);
}
functionChoiceRadioButton.addActionListener((ActionEvent e) -> {
// on click, take control
// check if fit function exists (could be calculated)
if (rawRatioDataModel.containsFitFunction(fitFunctionType)) {
rawRatioDataModel.setSelectedFitFunctionType(fitFunctionType);
if (targetDataModelView instanceof DataViewsOverlay) {
((DataViewsOverlay) targetDataModelView).getDownholeFractionationDataModel()//
.calculateWeightedMeanForEachStandard(rawRatioDataModel.getRawRatioModelName(), rawRatioDataModel.getSelectedFitFunction());
}
layoutFitFunctionViews(atleastOneFit, ((AbstractRawDataView) ((Component) e.getSource()).getParent().getParent()));
updatePlotsWithChanges(targetDataModelView);
updateReportTable();
}
// do nothing updatePlotsWithChanges(targetDataModelView);
});
fitFunctionButtonGroup.add(functionChoiceRadioButton);
return functionChoiceRadioButton;
}
/**
* Create a radio button
*
* @param controlsPanel
* the panel to add the button too
* @param group
* the radio button group
* @param cs
* the colourSpace that the button represents
*/
private void createRadioButton(final JPanel controlsPanel, final ButtonGroup group, final ColourSpace cs) {
final String name = cs.name();
final JRadioButton button = new JRadioButton(name);
button.setActionCommand(name);
controlsPanel.add(button);
group.add(button);
button.setSelected(cs == ColourSpace.RGB);
button.addActionListener(this);
}
/**
* Create a radio button
*
* @param colourspacesPanel
* the panel to add the button too
* @param group
* the radio button group
* @param cs
* the colourSpace that the button represents
*/
private void createRadioButton(final JPanel colourspacesPanel, final ButtonGroup group, final ColourSpace cs) {
final String name = cs.name();
final JRadioButton button = new JRadioButton(name);
button.setActionCommand("ColourSpace." + name);
colourspacesPanel.add(button);
group.add(button);
button.setSelected(cs == ColourSpace.HS);
button.addActionListener(this);
}