下面列出了javax.swing.JRadioButton#setForeground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private JRadioButton createRadioButton(String name, Font font) {
JRadioButton chk = new JRadioButton(StringResource.get(name));
chk.setIcon(ImageResource.getIcon("unchecked.png", 16, 16));
chk.setSelectedIcon(ImageResource.getIcon("checked.png", 16, 16));
chk.setOpaque(false);
chk.setFocusPainted(false);
chk.setForeground(Color.WHITE);
chk.setFont(font);
return chk;
}
private JRadioButton createRadioButton(String name, Font font) {
JRadioButton chk = new JRadioButton(StringResource.get(name));
chk.setIcon(ImageResource.getIcon("unchecked.png", 16, 16));
chk.setSelectedIcon(ImageResource.getIcon("checked.png", 16, 16));
chk.setOpaque(false);
chk.setFocusPainted(false);
chk.setForeground(Color.WHITE);
chk.setFont(font);
return chk;
}
/**
* Creates the main frame for <code>this</code> sample.
*/
public ColorizationFactor() {
super("Colorization factor");
this.setLayout(new BorderLayout());
final JPanel panel = new JPanel(new FlowLayout());
JButton button = new JButton("sample");
button.setBackground(Color.yellow);
button.setForeground(Color.red);
panel.add(button);
JCheckBox checkbox = new JCheckBox("sample");
checkbox.setSelected(true);
checkbox.setBackground(Color.green.brighter());
checkbox.setForeground(Color.blue.darker());
panel.add(checkbox);
JRadioButton radiobutton = new JRadioButton("sample");
radiobutton.setSelected(true);
radiobutton.setBackground(Color.yellow);
radiobutton.setForeground(Color.green.darker());
panel.add(radiobutton);
this.add(panel, BorderLayout.CENTER);
JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final JSlider colorizationSlider = new JSlider(0, 100, 50);
colorizationSlider.addChangeListener((ChangeEvent e) -> {
double val = colorizationSlider.getValue() / 100.0;
SubstanceCortex.ComponentOrParentChainScope.setColorizationFactor(panel, val);
panel.repaint();
});
controls.add(colorizationSlider);
this.add(controls, BorderLayout.SOUTH);
this.setSize(400, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void installUI (JComponent c) {
super.installUI (c);
JRadioButton radioButton = (JRadioButton) c;
radioButton.setFont (UIManager.getFont ("RadioButton.font"));
radioButton.setBackground (UIManager.getColor ("RadioButton.background"));
radioButton.setForeground (UIManager.getColor ("RadioButton.foreground"));
radioButton.setIcon (UIManager.getIcon ("RadioButton.icon"));
radioButton.setSelectedIcon (UIManager.getIcon ("RadioButton.selectedIcon"));
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
public static JRadioButton createJRadioButton(String description) {
JRadioButton radioButton = new JRadioButton(description);
radioButton.setForeground(ColorPalette.FOREGROUND_COLOR);
radioButton.setFont(Fonts.FONT);
return radioButton;
}
private void SetupUncertaintyModeButtonGroup () {
uncertaintyModeGroup = new ButtonGroup();
ActionListener uncertaintyModeActionListener = new ActionListener() {
public void actionPerformed ( ActionEvent e ) {
propertySupport.firePropertyChange(//
UNCERTAINTY_MODE_PROPERTY,
"",
((JRadioButton) e.getSource()).getActionCommand() );
}
};
JRadioButton analyticalRB = new JRadioButton( "Analytical", true );
analyticalRB.setActionCommand( "Analytical" );
uncertaintyModeGroup.add( analyticalRB );
analyticalRB.setOpaque( false );
analyticalRB.setForeground( new java.awt.Color( 204, 0, 0 ) );
analyticalRB.setFont( new Font( "SansSerif", Font.BOLD, 9 ) );
analyticalRB.setBounds( 1, 2, 130, 16 );
analyticalRB.addActionListener( uncertaintyModeActionListener );
add( analyticalRB, javax.swing.JLayeredPane.DEFAULT_LAYER );
JRadioButton tracerRB = new JRadioButton( "+ Tracer", false );
tracerRB.setActionCommand( "Tracer" );
uncertaintyModeGroup.add( tracerRB );
tracerRB.setOpaque( false );
tracerRB.setForeground( new java.awt.Color( 204, 0, 0 ) );
tracerRB.setFont( new Font( "SansSerif", Font.BOLD, 9 ) );
tracerRB.setBounds( 1, 21, 130, 16 );
tracerRB.addActionListener( uncertaintyModeActionListener );
add( tracerRB, javax.swing.JLayeredPane.DEFAULT_LAYER );
JRadioButton lambdaRB = new JRadioButton( "+ decay constants", false );
lambdaRB.setActionCommand( "Lambda" );
uncertaintyModeGroup.add( lambdaRB );
lambdaRB.setOpaque( false );
lambdaRB.setForeground( new java.awt.Color( 204, 0, 0 ) );
lambdaRB.setFont( new Font( "SansSerif", Font.BOLD, 9 ) );
lambdaRB.setBounds( 1, 40, 130, 16 );
lambdaRB.addActionListener( uncertaintyModeActionListener );
add( lambdaRB, javax.swing.JLayeredPane.DEFAULT_LAYER );
}
private JPanel createEphModeSelector(Color bgClr, Color fgClr){
JPanel panel = new JPanel();
ActionListener modeListener = new ActionListener(){
public void actionPerformed(ActionEvent e) {
ephMode = Mode.valueOf(e.getActionCommand());
if (ephMode.isMonthly()){
tablePanel.setScrollPaneSize(monthyTableSize);
((CalendarSpinner) monthChooser).setDateFormat(CalendarSpinner.FMT_YEAR);
}else{
tablePanel.setScrollPaneSize(dailyTableSize);
int row = ephTable.getSelectedRow();
if (row != -1){
ephDate.set(Calendar.MONTH, row);
}
monthChooser.setSelectedDate(ephDate.getTime());
((CalendarSpinner) monthChooser).setDateFormat(CalendarSpinner.FMT_MONTH_YEAR);
}
updateEphTable();
}
};
ButtonGroup bg = new ButtonGroup();
for(Mode m : Mode.values()){
JRadioButton button = new JRadioButton(m.toString());
bg.add(button);
button.setActionCommand(m.name());
button.addActionListener(modeListener);
panel.add(button);
button.setBackground(bgClr);
button.setForeground(fgClr);
if ( m == ephMode) {
button.setSelected(true);
}
}
panel.setBackground(bgClr);
return panel;
}