Tag: setbackground

JPanel setBackground(Color.BLACK)什么都不做

我有以下的自定义JPanel,我已经使用Netbeans GUI构建器将其添加到我的框架中,但背景不会改变! 我可以看到圆圈,用g.fillOval()绘图。 怎么了? public class Board extends JPanel{ private Player player; public Board(){ setOpaque(false); setBackground(Color.BLACK); } public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.red); g.fillOval(player.getxCenter(), player.getyCenter(), player.getRadius(), player.getRadius()); } public void updatePlayer(Player player){ this.player=player; } }

为什么setBackground到JButton不起作用?

我有以下简单的代码: btn = new JButton(); btn.setBackground(backgroundColor) 我用的时候工作过: UIManager.setLookAndFeel(“com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel”); 但是在我评论了上述内容后,它停止了工作。 有没有人知道为什么会发生这种情况以及如何在不使用明确外观的情况下为按钮设置背景颜色? 添加 在我看来,我需要使用getBackground 。 但是我不知道怎么做。

Java JFrame背景颜色不起作用

我试过用: frame1.getContentPane().setBackground(Color.yellow); 但它没有用。 谁能帮我? import java.awt.*; import java.awt.Color; public class PlayGame { public static void main(String[] args) { GameFrame frame1 = new GameFrame(); frame1.getContentPane().setBackground(Color.yellow); // Set Icon Image icon = Toolkit.getDefaultToolkit().getImage(“image/poker_icon.gif”); frame1.setIconImage(icon); frame1.setVisible(true); frame1.setSize(600, 700); frame1.setTitle(“Card Game”); // Set to exit on close frame1.setDefaultCloseOperation(GameFrame.EXIT_ON_CLOSE); } } GameFrame import javax.swing.*; import java.awt.*; import java.awt.event.*; public class […]

更改背景颜色可编辑JComboBox

我正在编写一个JFrame表单中的可编辑combobox,但我想改变背景颜色。 程序如何工作:如果我点击“按”按钮,那么combobox的背景需要变成黑色。 我试过了: 1。 cbo.setBackground(Color.BLACK); 但它没有做任何事情 2 cbo.getEditor().getEditorComponent().setBackground(Color.BLACK); ((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true); 做这个: 代码示例: public class NewJFrame extends javax.swing.JFrame { private JComboBox cboCategorie; public NewJFrame() { initComponents(); cboCategorie = new JComboBox(); cboCategorie.setBounds(10, 10, 250, 26); cboCategorie.setVisible(true); cboCategorie.setEditable(true); this.add(cboCategorie); } private void pressActionPerformed(java.awt.event.ActionEvent evt) { cboCategorie.getEditor().getEditorComponent().setBackground(Color.BLACK); ((JTextField) cboCategorie.getEditor().getEditorComponent()).setOpaque(true); } 我正在使用Java JDK7 任何sugestions?