javax.swing.JComponent.setForeground()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中javax.swing.JComponent.setForeground()方法的一些代码示例,展示了JComponent.setForeground()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.setForeground()方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:setForeground

JComponent.setForeground介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

JProgressBar jpb = new JProgressBar();
jpb.setUI(new MyProgressUI());
jpb.setForeground(Color.blue);
jpb.setIndeterminate(true);
this.add(jpb);
JFrame f = new JFrame("ProgressBarUITest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

代码示例来源:origin: stackoverflow.com

JList list = new JList(files);
    list.setCellRenderer(new FileListCellRenderer());
    gui.add(new JScrollPane(list));
  label.setBackground(backgroundSelectionColor);
  label.setForeground(textSelectionColor);
} else {
  label.setBackground(backgroundNonSelectionColor);
  label.setForeground(textNonSelectionColor);

代码示例来源:origin: stackoverflow.com

setForeground(standardColor);
setBorder(standardBorder);
setCursor( new Cursor(Cursor.HAND_CURSOR) );
setForeground(activeColor);
setBorder(activeBorder);
try {
  e.printStackTrace();
setForeground(standardColor);
setBorder(standardBorder);
setForeground(hoverColor);
setBorder(hoverBorder);
setForeground(standardColor);
setBorder(standardBorder);
setForeground(standardColor);
setBorder(standardBorder);
setForeground(hoverColor);
setBorder(hoverBorder);
p.add(linkLabelFile);
p.add(linkLabelWeb);

代码示例来源:origin: stackoverflow.com

public CButton(String txt) {
  super(txt);
  setForeground(Color.WHITE);
  setFont(getFont().deriveFont(Font.BOLD, 13));
  setContentAreaFilled(false);
    setForeground(Color.black);
    setForeground(Color.white);
  add(usrNameLabel, labCnst);
  add(usrNameFeild, txtCnst);
  add(passwordLabel, labCnst);
  add(passFeild, txtCnst);
  comp.setForeground(Color.WHITE);
  comp.setFont(getFont().deriveFont(Font.BOLD, 13));
      JFrame frame = new JFrame("Demo: LogIn Dialogue");
      frame.add(new MainContainer());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

add(jScrollPane1);
  label.setBackground(backgroundSelectionColor);
  label.setForeground(textSelectionColor);
} else {
  label.setBackground(backgroundNonSelectionColor);
  label.setForeground(textNonSelectionColor);

代码示例来源:origin: stackoverflow.com

import java.awt.*;
import javax.swing.*;
import java.util.Random;

public class Bucky extends JApplet {
  private String s = "";
  private JLabel label = new JLabel("", SwingConstants.CENTER);

  @Override
  public void init() {
   Random rand = new Random();
   float red = rand.nextFloat();
   float green = rand.nextFloat();
   float blue = rand.nextFloat();

   Color randomColor = new Color(red, green, blue);
   label.setForeground(randomColor);
   add(label);
   s = JOptionPane.showInputDialog(this, "Enter a String");
   label.setText(s);
  }

}

代码示例来源:origin: stackoverflow.com

private JFrame frame = new JFrame("sssssssss");
private JButton tip1Null = new JButton(" test button ");
  compound2 = BorderFactory.createCompoundBorder(empty, new OldRoundedBorderLine(crl2));
  tip1Null.setFont(new Font("Serif", Font.BOLD, 14));
  tip1Null.setForeground(Color.darkGray);
  tip1Null.setPreferredSize(new Dimension(50, 30));
  tip1Null.addActionListener(new java.awt.event.ActionListener() {
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(tip1Null, BorderLayout.CENTER);
  frame.setLocation(150, 150);
  frame.setPreferredSize(new Dimension(310, 75));
  frame.setLocationRelativeTo(null);
  frame.pack();
  frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

package test;

import java.awt.*;
import javax.swing.*;

public class CustomPanel extends JPanel
{
  public CustomPanel()
  {
    setOpaque(true);
    setBackground(Color.DARK_GRAY);

    JLabel label = new JLabel(
      "I am a JLabel from Java Swing", JLabel.CENTER);
    label.setOpaque(false); 
    label.setForeground(Color.WHITE);
    add(label); 
  }

  @Override
  public Dimension getPreferredSize()
  {
    return (new Dimension(500, 300));
  }
}

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(500, 300);
final DefaultListModel listModel = new DefaultListModel();
final JList panel = new JList(listModel);
panel.setBackground(new Color(128, 0, 40));
panel.setForeground(new Color(240, 240, 240));
frame.add(panel);
System.setProperty("java.net.preferIPv4Stack", "true");
final JChannel channel = new JChannel("udp.xml");

代码示例来源:origin: stackoverflow.com

add(useraccountnumberJL);
useraccountnumberJL.setText(panel.getUseraccountnumberJTFText());
useraccountnumberJL.setBounds( 100, 75, 625, 200 );
submitJB.setForeground( Color.red );
submitJB.setBackground( Color.YELLOW );
add( submitJB); 
add( welcomeMessage = new JLabel( "Welcome to Building Another Panel!!" ) );
welcomeMessage.setBounds(0,0,50,23);

代码示例来源:origin: stackoverflow.com

private JFrame frame = new JFrame();
    setBackground(Color.gray);
    label = new JLabel(" X ");
    label.setOpaque(true);
    label.setBackground(Color.RED);
    label.setForeground(Color.WHITE);
    setBackground(Color.black);
    setLayout(new FlowLayout(FlowLayout.RIGHT));
    add(label);
    add(new MainPanel(), BorderLayout.CENTER);
    add(new BorderPanel(), BorderLayout.PAGE_START);
    setBorder(new LineBorder(Color.BLACK, 5));
  frame.setUndecorated(true);
  frame.add(new OutsidePanel());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);

代码示例来源:origin: net.sf.jt400/jt400

/**
 * Adds the button to the specified panel.                
 * @param button    number of the button in our button array.
 * @param label        the text shown on the button.
 * @param constraints        The GridBagConstraints of this button.
 * @param panel        The panel to attach the button to.   
 */
private void addbutton(int button,String l,GridBagConstraints c,JPanel p) {
  b[button] = new JButton(l);
  b[button].setBackground(Color.black);
  b[button].setForeground(Color.white);
  b[button].addActionListener(new CommTraceListener(this));
  b[button].addKeyListener(new CommTraceListener(this));
  gridbag.setConstraints(b[button],c);
  p.add(b[button]);
}

代码示例来源:origin: stackoverflow.com

try {
      textfield.setText("");
      textfield.setForeground(foregroundColor);
    } finally {
      registerListeners();
    try {
      textfield.setText(ghostText);
      textfield.setForeground(ghostColor);
    } finally {
      registerListeners();
JFrame frame = new JFrame("Test ghost text");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JTextField textField = new JTextField();
GhostText ghostText = new GhostText(textField, "Please enter some text here...");
textField.setPreferredSize(new Dimension(300, 24));
panel.add(textField);
panel.add(button);
frame.add(panel);
frame.pack();
frame.setVisible(true);
button.grabFocus();

代码示例来源:origin: stackoverflow.com

alarmMessage.setText("Alarm !");
alarmMessage.setFont(new Font("Cambria",Font.BOLD,100));
alarmMessage.setForeground(Color.CYAN);
panel.add(alarmMessage);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0,0,screenSize.width,screenSize.height);
panel.setBackground(Color.black);
add(panel);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.add(f);
frame.add(p);
frame.pack();
frame.setVisible(true);
suggestionsPanel.setBackground(popUpBackground);
            lastFocusableIndex = 0;
            sl.setFocused(false);
            autoSuggestionPopUpWindow.setVisible(false);
            setFocusToTextField();
      autoSuggestionPopUpWindow.setVisible(false);
      setFocusToTextField();
suggestionsPanel.add(suggestionLabel);
setForeground(suggestionsTextColor);

代码示例来源:origin: stackoverflow.com

TableColumn tc = table.getColumnModel().getColumn(BOOLEAN_COL);
tc.setHeaderRenderer(new SelectAllHeader(table, BOOLEAN_COL));
JFrame f = new JFrame();
f.add(new JScrollPane(table));
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
this.setFont(UIManager.getFont("TableHeader.font"));
this.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
this.setBackground(UIManager.getColor("TableHeader.background"));
this.setForeground(UIManager.getColor("TableHeader.foreground"));

代码示例来源:origin: stackoverflow.com

JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jtp.setBackgroundAt(2, Color.BLUE);
    f.add(jtp, BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
  this.mask = color.getRGB();
  this.index = index;
  this.setBackground(color);
  label.setForeground(color);
  this.add(label);
  timer.start();
public void actionPerformed(ActionEvent e) {
  color = new Color(rnd.nextInt() & mask);
  this.setBackground(color);
  jtp.setBackgroundAt(index, original);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("JAVA");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComboBox cmb = new JComboBox(strings);
ComboBoxRenderer renderer = new ComboBoxRenderer(cmb);
frame.add(cmb);
frame.pack();
frame.setVisible(true);
textPanel.add(this);
text = new JLabel();
text.setOpaque(true);
text.setFont(combo.getFont());
textPanel.add(text);
  setBackground(list.getSelectionBackground());
  setBackground(Color.WHITE);
text.setBackground(getBackground());
  text.setForeground(colors[index]);

代码示例来源:origin: stackoverflow.com

JFrame f = new JFrame();
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  createTab("Blues", Color.BLUE);
  f.add(jtp, BorderLayout.CENTER);
  f.pack();
  f.setVisible(true);
this.icon = icon;
this.mask = icon.color.getRGB();
this.setBackground(icon.color);
label.setForeground(icon.color);
this.add(label);
timer.start();
this.setBackground(new Color(rnd.nextInt() & mask));
this.icon.update(count += rnd.nextInt(8));
this.parent.repaint();

代码示例来源:origin: stackoverflow.com

DefaultTableModel model1 = new DefaultTableModel(data1, headers);
final JTable jTable1 = new JTable(model1);
jTable1.setBackground(Color.orange);
jTable1.setForeground(Color.blue);
jTable1.setRowHeight(24);
jTable1.setFont(new Font("Arial", Font.BOLD, 12));
JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayout(3, 0, 10, 10));
panel1.add(sp1);
panel1.add(sp2);
panel1.add(sp3);
JFrame frame = new JFrame("tableSelection");
frame.add(panel1);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

相关文章

JComponent类方法