JAVA 2008. 8. 24. 21:59

[스윙] JEditorPane에서 html 을 표현하도록 해주는 방법

contentType 을 text/html 로 해준다.

제목: [스윙] JTable 에서 row 단위로 색깔을 다르게 주고 싶을때

JTable 생성시 prepareRenderer 메소드를 다음과 같이 재정의 해준다.

JTable table = new JTable() {
             public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                 Component c = super.prepareRenderer(renderer, row, column);
                 if (!isCellSelected(row, column)) {
                     if (row % 2 == 0) {
                        c.setBackground(Color.blue);
                     } else {
                        c.setBackground(Color.red);                        
                     }
                 }
                 
               return c;
             }
         };

제목: [스윙]SwingUtilities.invokeLater 와 SwingUtilities.invokeAndWait 의 차이점

SwingUtilities.invokeLater 와 SwingUtilities.invokeAndWait 메소드는 외부에서 다이얼로그와 같은 창을
띄울때 다이얼로그에 포커스가 가도록 해주는 함수들이다.

그런데 위의 두함수의 차이점은 invokeLater의 경우 호출한쪽에서 제어권을 가지지 않는경우이다 즉 비동기화를 의미하며 invokeAndWait 는 그 반대가 된다.



제목: [스윙] JLabel 에서 background 에 색깔을 주려면

opaque 를 true 로 해줘야 색깔이 바뀐다

제목: [스윙] JTable의 데이타가 변했는데도 화면에 변화가 생기지 않을때

JTable내의 데이타모델을 불러와서 다음과같이 2개를 메소드를 호출해준다.
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
dtm.fireTableStructureChanged();
dtm.fireTableDataChanged();

 

제목: [스윙] JOptionPane 이 스레드에 의해서 호출이 될때 제대로 동작하지 않을때

JOptionPane은 자신의 부모창이 아닌 외부 스레드에 의해서 호출이 될때 버튼이 활성화되지 않는 문제점이 있다. 이때 다음과 같이 해주면 된다
SwingUtilities.invokeAndWait(new Runnable()              {                
public void run() { JOptionPane.showXXXX...};              
});

 

 

제목: [스윙] DefaultTableModel 을 사용하면서 CheckBox모양이 나타나지 않을때

다음과 같이 재정의해주면 됩니다.
    public Class getColumnClass(int c) {
       return getValueAt(0, c).getClass();
    }

 

 

제목: [스윙] JComboBox 에서 아이템이 변할때 한번만 이벤트를 먹도록 하는 방법

if(e.getStateChange() == e.SELECTED){
}

public void itemStateChanged(java.awt.event.ItemEvent e) {      
   if(e.getStateChange() == e.SELECTED){
   }
}

posted by 나는너의힘
: