2014-09-26 4 views
1

UIManager 설정을 사용해 JOptionPane의 Font를 변경 했습니다만, 버튼의 속성을 변경하는 프로퍼티를 검색 할 수 없습니다. 예를 들어. 아래 텍스트와 같이 테두리를 제거하고 싶습니다. 또한 아래와 같이 Y와 N에서 밑줄을 제거하고 싶습니다. 또한JOptionPane 버튼의 속성과 배경색을 변경합니다.

enter image description here

, 나는 뭔가 다른이 오프 화이트 색상위한 JOptionPane의 배경 색상을 변경할 수 있습니까?

+0

현실적으로 이것은 매우 간단합니다. ['JOptionPane.showOptionDialog (Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object [] options, Object initialValue)'] (http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html#showOptionDialog (java.awt.Component, % 20java.lang. Object, % 20java.lang.String, % 20int, % 20int, % 20javax.swing.Icon, % 20java.lang.Object [], % 20java.lang.Object)), 이는 사용자 정의 버튼을 'options' 매개 변수 – MadProgrammer

+0

하지만 대화 상자의 상태를 관리하는 것은 쉬운 일이 아닙니다. – MadProgrammer

+0

[example] (http://stackoverflow.com/questions/14591089/joptionpane-passing-custom- 버튼/14591165 # 14591165) – MadProgrammer

답변

0

개별 대화 상자를 변경할 수 있습니다

당신은 customJDialog 및 사용자 정의 JOptionPane에 필요합니다. 버튼은 연상 기호와 일치하는 첫 번째 글자에 밑줄을 긋습니다. 그것을 사용되지 않는 것으로 변경하십시오. 사각형은 버튼 포커스에 관한 것입니다.

JDialog dialog = new JDialog(); 

JOptionPane pane = new JOptionPane("Some Message", 
JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_OPTION); 

List<JButton> list = SwingUtils.getDescendantsOfType(JButton.class, pane); 
//this method is part of the SwingUtils. It is free to use. You can download it from the link. 

pane.setBackground(Color.green); //this does not completely change the background. I am not sure how you can change it completely 

for (JButton b : list) { 
    b.setMnemonic(0); //call it with an int or char that does not exist in your button. 
    b.setFocusable(false); //removes the rectangle 
    b.setBackground(Color.red); 
    //you can do more since you have direct access to the button 
} 

당신은 버튼 액션이 체크 아웃 JOptionPane에 자바 사용자와 경험이없는 경우 : Pressing Yes/No on embedded JOptionPane has no effect

SwingUtil 링크 :

당신이 라이브러리에 코드를 설정하려면 http://tips4java.wordpress.com/2008/11/13/swing-utils/ 읽기 : http://www.programcreek.com/2011/07/build-a-java-library-for-yourself/

+0

작동하면 매우 훌륭합니다! 고마워. 나는 곧 이것을 시도 할 것이다 :) – Gagan93

관련 문제