JFrameの背景色を変更する方法

通常、JFrameの背景を変更するには、JFrameメソッドsetBackground(カラー c):

frame.setBackground(Color.BLUE)です。

JFrameには、java Colorクラス:

  • RGB値
  • brighterなどのメソッドを使用して適用できるトリックが含まれています。 暗いまたは明るい

コンポーネントの色を取得する他のメソッドもあります。

JFrameの例 setBackground(color) 

このコードをIDEでテストできます:

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;

public class Test extends JFrame{

public static void main(String[] args) {

JFrame frame = new JFrame("JFrame test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);

frame.setPreferredSize(new Dimension(400, 300));
frame.getContentPane().setBackground(Color.ORANGE);
frame.pack();
frame.setVisible(true);
}
}
JFrameの背景を変更