Tôi đã sử dụng .setBackground
và .setForeground
và chúng không hoạt động, màu sắc giống như màu cam, không thể thay đổi.Làm cách nào để thay đổi màu JProgressBar?
16
A
Trả lời
22
Tôi nghĩ rằng những giá trị này là phù hợp với bạn
UIManager.put("ProgressBar.background", Color.ORANGE);
UIManager.put("ProgressBar.foreground", Color.BLUE);
UIManager.put("ProgressBar.selectionBackground", Color.RED);
UIManager.put("ProgressBar.selectionForeground", Color.GREEN);
14
Bạn nên thiết lập thuộc tính setStringPainted true:
progressBar.setStringPainted(true);
progressBar.setForeground(Color.blue);
progressBar.setString("10%");
Trông tốt. Hoặc là thay đổi L & F hoàn toàn.k 1+ –
+1 cho 'UIManager'; xem thêm [thay thế] này (http://stackoverflow.com/a/8886795/230513). – trashgod
1 cho câu trả lời này, nhưng tôi tự hỏi làm thế nào để biết 'giá trị của Key', làm thế nào tôi sẽ biết' UIManager.put (ProgressBar.whatElseCanIWriteHere, myValue) ', là có bất kỳ Doc, thảo luận về phần này, Nếu có là một, xin vui lòng chỉ cho tôi vào nó, tôi rất biết ơn :-) –