Stacked Q&A

.setForeground(Color.red); not working\?
  • 1 voting
  • 2022-06-26 00:00

    JPanel mygame = new JPanel();
    mygame.setLayout(new BorderLayout()); 
    
    mygame.add(new JButton("Start Game"), 
    
    mygame.setForeground(Color.red);
    
    BorderLayout.WEST); 
    

    This is how I input the code, and I tried diff ways following tutorials but colour of "start game" text will not change. also set background to gray but it stays default color? Can't see what I'm doing wrong, followed tutorial only changed bits for my specific code? help appreciated

  • 2 1337 0 0
첨부 파일
답변
총 2개의 답변이있습니다.
  • 답변일: 2022-06-26 00:00

    Instead of changing the foreground colour of JPanel, change the foreground colour of JButton

    JButton button = new JButton("Start Game")
    JPanel mygame = new JPanel();
    
    button.setForeground(Color.red);
    mygame.setLayout(new BorderLayout()); 
    mygame.add(button);  
    
  • 0 0 퍼블 채택!
Tages
    활동순위
    유저
      파트너사