当前位置: 首页>>代码示例>>Java>>正文


Java JRadioButton.setBackground方法代码示例

本文整理汇总了Java中javax.swing.JRadioButton.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java JRadioButton.setBackground方法的具体用法?Java JRadioButton.setBackground怎么用?Java JRadioButton.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JRadioButton的用法示例。


在下文中一共展示了JRadioButton.setBackground方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addCheckBox

import javax.swing.JRadioButton; //导入方法依赖的package包/类
/** Create an on-off check box.
 *  @param name The name used to identify the entry (when calling get).
 *  @param label The label to attach to the entry.
 *  @param defaultValue The default value (true for on).
 */
public void addCheckBox(String name, String label, boolean defaultValue) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    JRadioButton checkbox = new JRadioButton();
    checkbox.setBackground(_background);
    checkbox.setOpaque(false);
    checkbox.setSelected(defaultValue);
    _addPair(name, lbl, checkbox, checkbox);
    // Add the listener last so that there is no notification
    // of the first value.
    checkbox.addItemListener(new QueryItemListener(name));
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:18,代码来源:Query.java

示例2: addRadioButtons

import javax.swing.JRadioButton; //导入方法依赖的package包/类
/** 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);
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:46,代码来源:Query.java

示例3: addDPIDefaultVals

import javax.swing.JRadioButton; //导入方法依赖的package包/类
/**
 * Add a list of radio buttons, representing default, generally used, values
 * for the DPI.
 */
private void addDPIDefaultVals() {
    // set the layout of the panel, based on the amount of elements to be displayed on it
    jPDefaultValues.setLayout(new GridLayout(DPI_VALUES.length, 1));

    for (int index = 0; index < DPI_VALUES.length; index++) {
        String text = DPI_VALUES[index] + " DPI";

        // create a radio button with the given text
        JRadioButton jrbDPIValues = new JRadioButton(text);

        // set its action command to a number for easier usage later (to retrieve the value of the DPI)
        jrbDPIValues.setActionCommand(Integer.toString(DPI_VALUES[index]));

        // add action listener to synchronize the text field with the radio buttons
        jrbDPIValues.addActionListener(e -> jFTFDPIValue.setValue(Integer.parseInt(bgScreenDPIs.getSelection().getActionCommand())));

        // add mouse listener to display the help message when the mouse is on top of the radio buttons
        jrbDPIValues.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jPDefaultValuesMouseEntered(evt);
            }
        });

        jrbDPIValues.setBackground(Color.white);

        // add the radio button to the button group
        bgScreenDPIs.add(jrbDPIValues);

        // add the radio button to the panel displaying it
        jPDefaultValues.add(jrbDPIValues);

        // select the radio button which has the same value as the user preffered one (if any)
        if (DPI_VALUES[index] == userPreferences.getPreferredDPI()) {
            jrbDPIValues.setSelected(true);
            jFTFDPIValue.setValue(DPI_VALUES[index]);
        }
    }
}
 
开发者ID:buni-rock,项目名称:Pixie,代码行数:44,代码来源:UserConfigs.java

示例4: createSizePanel

import javax.swing.JRadioButton; //导入方法依赖的package包/类
/**
 * @return
 */
private Component createSizePanel() {
	
	final ButtonGroup buttons = new ButtonGroup();
	JPanel jp = new MyJPanel("Node Size", Color.RED);
	
	mNodeSizeDegreeSlider = new JSlider(JSlider.HORIZONTAL);
	mNodeSizeDegreeSlider.setPreferredSize(new Dimension(180, 40));
	mNodeSizeDegreeSlider.setPaintTicks(true);
	mNodeSizeDegreeSlider.setBackground(Color.WHITE);
	mNodeSizeDegreeSlider.setValue(0);
	final JRadioButton degree = new JRadioButton("Degree");
	degree.setBackground(Color.WHITE);
	degree.setSelected(true);	
	buttons.add(degree);
	jp.add( degree );
	
	jp.add(mNodeSizeDegreeSlider);
	
	mNodeSizePageRankSlider = new JSlider(JSlider.HORIZONTAL);
	mNodeSizePageRankSlider.setPreferredSize(new Dimension(180, 40));
	mNodeSizePageRankSlider.setPaintTicks(true);
	mNodeSizePageRankSlider.setBackground(Color.WHITE);
	mNodeSizePageRankSlider.setEnabled( false );
	final JRadioButton rank = new JRadioButton("PageRank with Prior");
	rank.setBackground(Color.WHITE);
	buttons.add(rank);
	
	jp.add( rank );
	jp.add( mNodeSizePageRankSlider);

	ActionListener al = new ActionListener() {

		public void actionPerformed(ActionEvent e) {
			if( e.getSource() == rank) {
				mNodeSizePageRankSlider.setEnabled(true);
				mNodeSizeDegreeSlider.setEnabled(false);
			} 
			if ( e.getSource() == degree) {
				mNodeSizePageRankSlider.setEnabled(false);
				mNodeSizeDegreeSlider.setEnabled(true);
			}
		}
		
	};
	degree.addActionListener(al);
	rank.addActionListener(al);
	
	return jp;
}
 
开发者ID:dev-cuttlefish,项目名称:cuttlefish,代码行数:53,代码来源:RankingDemo.java


注:本文中的javax.swing.JRadioButton.setBackground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。