JCombo width in JTable


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JCombo width in JTable

Hybrid View

  1. #1
    Join Date
    Nov 2004
    Posts
    1

    Question JCombo width in JTable

    Hi,
    I am wondering if anyone has had this prooblem before.
    I successfully created a JTable with a JCombo used as the editor for one of its columns. Everything OK but it seems I cannot control the width of the Combo box. The combo shows a bunch of infos that are actually wider than the data that is going to be stored in the table cell which is essentially an ID. Ideally I would like the combo box to be much wider than the table column but it seems its maximum width is set by the column width.
    I tried to play with the combo minimum maximum and preferredSize properties but with no success.

    Any suggestions ?

  2. #2
    Join Date
    Oct 2004
    Posts
    25
    You have to extend the MetalComboBoxUI, you need something like this:

    Code:
    	
    class MyComboBoxUI extends MetalComboBoxUI {
    ..............
    		protected ComboPopup createPopup() {
    			return new MetalComboPopup(comboBox) {
    				public void show() {
    					Dimension popupSize = ((MyComboBox) comboBox).getPopupSize();
    					//if (popupSize.width < getPopupWidth()) {
    					//	popupSize.width = getPopupWidth();
    					//}
    
    					popupSize.setSize(popupSize.width, getPopupHeightForRowCount(comboBox.getMaximumRowCount()));
    					Rectangle popupBounds = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
    					scroller.setMaximumSize(popupBounds.getSize());
    					scroller.setPreferredSize(popupBounds.getSize());
    					scroller.setMinimumSize(popupBounds.getSize());
    					list.invalidate();
    
    					int selectedIndex = comboBox.getSelectedIndex();
    					if (selectedIndex == -1) {
    						list.clearSelection();
    					} else {
    						list.setSelectedIndex(selectedIndex);
    					}
    					list.ensureIndexIsVisible(list.getSelectedIndex());
    					setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled());
    					show(comboBox, popupBounds.x, popupBounds.y);
    				}
    			};
    		}
    }
    or you can use the components TComboBox and SScrolledTable from
    eva/3 Application Builder

    Best Regards
    floaty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center