本文整理汇总了Java中javax.swing.JPanel.setForeground方法的典型用法代码示例。如果您正苦于以下问题:Java JPanel.setForeground方法的具体用法?Java JPanel.setForeground怎么用?Java JPanel.setForeground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JPanel
的用法示例。
在下文中一共展示了JPanel.setForeground方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getListCellRendererComponent
import javax.swing.JPanel; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent(JList<? extends Class<Process>> list, Class<Process> value, int index, boolean isSelected, boolean cellHasFocus) {
ProcessMetadata metadata = processMetadata.get(value);
// Title label
JLabel label = (JLabel) defaultRenderer.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus);
label.setText(metadata.getName());
label.setFont(new Font("Segoe UI", Font.BOLD, 12));
// Description label
JLabel description = new JLabel(metadata.getDescription());
description.setForeground(description.getForeground());
description.setBorder(BorderFactory.createEmptyBorder(1, 10, 3, 3));
description.setFont(new Font("Segoe UI", Font.PLAIN, 10));
if (metadata.getDescription() == null || metadata.getDescription().isEmpty()) {
description.setText("<No description specified>");
description.setForeground(description.getForeground().darker());
}
// Builds the component
JPanel component = new JPanel();
component.setLayout(new BorderLayout());
component.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
if (isSelected) {
component.setBackground(new Color(0xEDEDED));
} else {
if (index % 2 == 0) {
component.setBackground(new Color(0x555555));
}
}
component.add(label);
component.add(description, BorderLayout.SOUTH);
component.setOpaque(true);
component.setForeground(description.getForeground());
return component;
}
示例2: actionPerformed
import javax.swing.JPanel; //导入方法依赖的package包/类
public void actionPerformed (ActionEvent evt) {
centerPanel = new JPanel(new FlowLayout());
maxGenerationsLabel = new JLabel("Max Generations");
maxGenerationsField = new JTextField((new Integer(TSProblemModel.DEFAULT_GA_MAX_GENERATIONS)).toString(), 5);
popSizeLabel = new JLabel("Population Size");
popSizeField = new JTextField((new Integer(TSProblemModel.DEFAULT_GA_POP_SIZE)).toString(), 5);
mutationRateLabel = new JLabel("Mutation Rate");
mutationRateField = new JTextField((new Double(TSProblemModel.DEFAULT_MUTATION_RATE)).toString(), 5);
orderedCrossoverBox = new JCheckBox("Ordered Crossover", TSProblemModel.DEFAULT_ORDERED_CROSSOVER);
cyclicCrossoverBox = new JCheckBox("Cyclic Crossover", TSProblemModel.DEFAULT_CYCLIC_CROSSOVER);
pmxCrossoverBox = new JCheckBox("PMX Crossover", TSProblemModel.DEFAULT_PMX_CROSSOVER);
simulatedAnnealingBox = new JCheckBox("Simulated Annealing", TSProblemModel.DEFAULT_ANNEAL);
inverOverBox = new JCheckBox("Inver Over", TSProblemModel.DEFAULT_INVER_OVER);
centerPanel.add(maxGenerationsLabel);
centerPanel.add(maxGenerationsField);
centerPanel.add(popSizeLabel);
centerPanel.add(popSizeField);
centerPanel.add(mutationRateLabel);
centerPanel.add(mutationRateField);
centerPanel.add(orderedCrossoverBox);
centerPanel.add(cyclicCrossoverBox);
centerPanel.add(pmxCrossoverBox);
centerPanel.add(inverOverBox);
centerPanel.add(simulatedAnnealingBox);
centerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
centerPanel.setForeground(Color.getColor("202,198,202"));
getContentPane().add(centerPanel,BorderLayout.CENTER);
}
示例3: RRDraw
import javax.swing.JPanel; //导入方法依赖的package包/类
public RRDraw() {
super("File View Test Frame");
setSize(350, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
parent = this;
rrDrawPanel = new RRDrawPanel();
Container c = getContentPane();
// The default BorderLayout will work better.
// c.setLayout(new FlowLayout());
JButton openButton = new JButton("Open");
final JLabel statusbar = new JLabel("Output of your selection will go here");
openButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
JFileChooser chooser = new JFileChooser("images");
int option = chooser.showOpenDialog(parent);
if (option == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
BufferedImage loadImage = loadImage(file);
statusbar.setText(file.getName() + " size " + loadImage.getWidth() + "x" + loadImage.getHeight());
// setSize(loadImage.getWidth(), loadImage.getHeight());
rrDrawPanel.setSize(loadImage.getHeight(), loadImage.getWidth());
} else {
statusbar.setText("You cancelled.");
}
}
});
JPanel north = new JPanel();
north.add(openButton);
north.add(statusbar);
north.setBackground(Color.GRAY);
north.setForeground(Color.BLUE);
c.add(north, "First");
c.add(new JScrollPane(rrDrawPanel), "Center");
}
示例4: GASettings
import javax.swing.JPanel; //导入方法依赖的package包/类
/**
* Creates an instance of this class.
*/
protected GASettings () {
setTitle("Genetic Algorithm Settings");
setBounds(50,50,520,520);
centerPanel = new JPanel(new FlowLayout());
JPanel southPanel = new JPanel(new FlowLayout());
maxGenerationsLabel = new JLabel("Max Generations");
maxGenerationsField = new JTextField((new Integer(TSProblemModel.DEFAULT_GA_MAX_GENERATIONS)).toString(), 5);
popSizeLabel = new JLabel("Population Size");
popSizeField = new JTextField((new Integer(TSProblemModel.DEFAULT_GA_POP_SIZE)).toString(), 5);
mutationRateLabel = new JLabel("Mutation Rate");
mutationRateField = new JTextField((new Double(TSProblemModel.DEFAULT_MUTATION_RATE)).toString(), 5);
orderedCrossoverBox = new JCheckBox("Ordered Crossover", TSProblemModel.DEFAULT_ORDERED_CROSSOVER);
cyclicCrossoverBox = new JCheckBox("Cyclic Crossover", TSProblemModel.DEFAULT_CYCLIC_CROSSOVER);
pmxCrossoverBox = new JCheckBox("PMX Crossover", TSProblemModel.DEFAULT_PMX_CROSSOVER);
simulatedAnnealingBox = new JCheckBox("Simulated Annealing", TSProblemModel.DEFAULT_ANNEAL);
inverOverBox = new JCheckBox("Inver Over", TSProblemModel.DEFAULT_INVER_OVER);
centerPanel.add(maxGenerationsLabel);
centerPanel.add(maxGenerationsField);
centerPanel.add(popSizeLabel);
centerPanel.add(popSizeField);
centerPanel.add(mutationRateLabel);
centerPanel.add(mutationRateField);
centerPanel.add(orderedCrossoverBox);
centerPanel.add(cyclicCrossoverBox);
centerPanel.add(pmxCrossoverBox);
centerPanel.add(inverOverBox);
centerPanel.add(simulatedAnnealingBox);
centerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
centerPanel.setForeground(Color.getColor("202,198,202"));
// Create buttons and buttons panel
JPanel buttonsPanel = new JPanel(new FlowLayout());
buttonsPanel.add(new JButton(RESTORE_DEFAULT_ACTION));
buttonsPanel.add(new JButton(OK_ACTION));
buttonsPanel.add(new JButton(CANCEL_ACTION));
// Add buttons panel in South Panel
southPanel.add(buttonsPanel,BorderLayout.EAST);
// Add panels in Main Panel
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(southPanel,BorderLayout.SOUTH);
this.getContentPane().add(centerPanel,BorderLayout.CENTER);
}