回复:(jwc7213624)楼上的兄弟,你说的那个方法,我...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ForegroundTest extends JFrame{
private String strColors[];
private Color allColors[];
private JComboBox colorList;
private JLabel textLabel;
public ForegroundTest(){
strColors = new String[] {"Black", "White", "Red", "Blue"};
allColors = new Color[] {Color.BLACK, Color.WHITE, Color.RED, Color.BLUE};
textLabel = new JLabel("Draw my text here");
this.getContentPane().add(textLabel, BorderLayout.CENTER);
colorList = new JComboBox(strColors);
colorList.setEditable(false);
colorList.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
JComboBox source = (JComboBox)event.getSource();
textLabel.setForeground(allColors[source.getSelectedIndex()]);
}
});
this.getContentPane().add(colorList, BorderLayout.SOUTH);
this.setLocationRelativeTo(this.getParent());
this.pack();
}
public static void main(String[] args){
ForegroundTest test = new ForegroundTest();
test.setVisible(true);
}
}