Changeset 2043 in josm


Ignore:
Timestamp:
Sep 3, 2009 7:06:28 PM (4 years ago)
Author:
Gubaer
Message:

fixed #3076: Member columns don't auto-resize when the relation editor is resized

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r2040 r2043  
    321321 
    322322        final JScrollPane scrollPane = new JScrollPane(memberTable); 
    323         // this adapters ensures that the width of the tag table columns is adjusted 
    324         // to the width of the scroll pane viewport. Also tried to overwrite 
    325         // getPreferredViewportSize() in JTable, but did not work. 
    326         // 
    327         scrollPane.addComponentListener(new ComponentAdapter() { 
    328             @Override 
    329             public void componentResized(ComponentEvent e) { 
    330                 super.componentResized(e); 
    331                 Dimension d = scrollPane.getViewport().getExtentSize(); 
    332                 memberTable.adjustColumnWidth(d.width); 
    333             } 
    334         }); 
    335323 
    336324        GridBagConstraints gc = new GridBagConstraints(); 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r1884 r2043  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
     6import java.awt.Container; 
     7import java.awt.Dimension; 
    68import java.awt.event.ActionEvent; 
    79import java.awt.event.KeyEvent; 
     
    1315import javax.swing.JPopupMenu; 
    1416import javax.swing.JTable; 
     17import javax.swing.JViewport; 
    1518import javax.swing.KeyStroke; 
    1619import javax.swing.ListSelectionModel; 
     
    7275    } 
    7376 
    74     /** 
    75      * adjusts the width of the columns for the tag name and the tag value to the width of the 
    76      * scroll panes viewport. 
    77      * 
    78      * Note: {@see #getPreferredScrollableViewportSize()} did not work as expected 
    79      * 
    80      * @param scrollPaneWidth the width of the scroll panes viewport 
    81      */ 
    82     public void adjustColumnWidth(int scrollPaneWidth) { 
    83         TableColumnModel tcm = getColumnModel(); 
    84         int width = scrollPaneWidth; 
    85         width = width / 3; 
    86         if (width > 0) { 
    87             tcm.getColumn(0).setMinWidth(width); 
    88             tcm.getColumn(0).setMaxWidth(width); 
    89             tcm.getColumn(1).setMinWidth(width); 
    90             tcm.getColumn(1).setMaxWidth(width); 
    91             tcm.getColumn(2).setMinWidth(width); 
    92             tcm.getColumn(2).setMaxWidth(width); 
    93  
    94         } 
     77    @Override 
     78    public Dimension getPreferredSize(){ 
     79        Container c = getParent(); 
     80        while(c != null && ! (c instanceof JViewport)) { 
     81            c = c.getParent(); 
     82        } 
     83        if (c != null) { 
     84            Dimension d = super.getPreferredSize(); 
     85            d.width = c.getSize().width; 
     86            return d; 
     87        } 
     88        return super.getPreferredSize(); 
    9589    } 
    9690 
Note: See TracChangeset for help on using the changeset viewer.