KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   HTML  JAVA   Swing   Webtip  Lyric  Free sheet music  Ringtones
java,jtable,jtree,swing Return to JAVA table list

Best books about JAVA programming:

JAVA JTable JButton in JTable header

The following code add JComboBox to Jtable columns. This example involves 2 files: SmallCellComboExample.java and SteppedComboBox.java

//Example modified from http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples2.html
/**
* @version 1.0 12/03/98
*/


import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;
import javax.swing.plaf.basic.*;

class SteppedComboBoxUI extends MetalComboBoxUI {
protected ComboPopup createPopup() {
BasicComboPopup popup = new BasicComboPopup( comboBox ) {

public void show() {
Dimension popupSize = ((SteppedComboBox)comboBox).getPopupSize();
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 );
}
};
popup.getAccessibleContext().setAccessibleParent(comboBox);
return popup;
}
}


public class SteppedComboBox extends JComboBox {
protected int popupWidth;

public SteppedComboBox(ComboBoxModel aModel) {
super(aModel);
setUI(new SteppedComboBoxUI());
popupWidth = 0;
}

public SteppedComboBox(final Object[] items) {
super(items);
setUI(new SteppedComboBoxUI());
popupWidth = 0;
}

public SteppedComboBox(Vector items) {
super(items);
setUI(new SteppedComboBoxUI());
popupWidth = 0;
}


public void setPopupWidth(int width) {
popupWidth = width;
}

public Dimension getPopupSize() {
Dimension size = getSize();
if (popupWidth < 1) popupWidth = size.width;
return new Dimension(popupWidth, size.height);
}
}

 


Sponsored link
Java JTabbedPane
JTabbedPane Preview List
Java JComboBox
JComboBox Preview List
Java JTooltip
JTooltip Preview List
Java JList
JList Preview List
Java JTree
JTree Preview List 1
JTree Preview List 2
JAVA JTable
JTable Preview List 1
JTable Preview List 2
JTable Preview List 3
JTable Preview List 4
JTable Preview List 5
JTable Preview List 6
JTable Preview List 7
JAVA Jslide
JSlide Preview List

 

 

Best books about JAVA programming from Amazon
Professional Java, JDK 5 Edition (Paperback Simply Java Programming: An Application-Driven Tutorial Approach (Paperback) Effective Java Programming Language Guide (Paperback) Head First Java, 2nd Edition (Paperback) Java : An Introduction to Problem Solving and Programming (4th Edition)

 

Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © kidslovepc.com All rights reserved(new). Privacy|Copyright
designed by info@kidslovepc.com

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer