2012-10-26 4 views

답변

11

대신 ’Foreground’

로직은 Nimbus Look and Feel

금속 L에 대해 상이 할 수 & F의 ’Background’ 변경해야

enter image description here

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

public class GridBagSeparator1 { 

    public static void main(String[] args) { 
     JFrame frame = new JFrame("Laying Out Components in a Grid"); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

     JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL); 
     sep.setBackground(Color.black); 
     JSeparator sep1 = new JSeparator(SwingConstants.HORIZONTAL); 
     sep1.setBackground(Color.blue); 
     JSeparator sep2 = new JSeparator(SwingConstants.HORIZONTAL); 
     sep2.setBackground(Color.green); 
     JSeparator sep3 = new JSeparator(SwingConstants.HORIZONTAL); 
     sep3.setBackground(Color.red); 

     frame.setLayout(new GridLayout(4, 0)); 
     frame.add(sep); 
     frame.add(sep1); 
     frame.add(sep2); 
     frame.add(sep3); 
     frame.pack(); 
     frame.setVisible(true); 
    } 
} 
+2

배경을 변경해도 문제가 해결되지 않습니다. 나는 Mac에서 인터페이스를 구축하기 위해 Netbeans GUI 빌더 인 Matiss를 사용하고있다. 어쩌면 모양과 느낌의 제한 일 수 있습니다. – nathan

+4

'UIManager'를 사용하고'Separator.foreground'를 변경해야 할 수도 있습니다. – trashgod

+4

Sythetica Look and Feel에서는 배경을 변경하고 불투명 속성을 true로 설정해야했습니다. –

4

과 구분자는 2 색의 하나를 가지고 라인, 하나는 그림자. 배경색과 배경색을 각각 변경할 수 있습니다.

JSeparator sep = new JSeparator(); 
sep.setForeground(Color.green); // top line color 
sep.setBackground(Color.green.brighter()); // bottom line color 
관련 문제