Code
combo02.setLayout(new LayoutManager() {
@Override public void addLayoutComponent(String name, Component comp) {}
@Override public void removeLayoutComponent(Component comp) {}
@Override public Dimension preferredLayoutSize(Container parent) {
return parent.getPreferredSize();
}
@Override public Dimension minimumLayoutSize(Container parent) {
return parent.getMinimumSize();
}
@Override public void layoutContainer(Container parent) {
if(!(parent instanceof JComboBox)) return;
JComboBox cb = (JComboBox)parent;
int width = cb.getWidth();
int height = cb.getHeight();
Insets insets = cb.getInsets();
int buttonHeight = height - (insets.top + insets.bottom);
int buttonWidth = buttonHeight;
int labelWidth = buttonHeight;
int loupeWidth = buttonHeight;
JButton arrowButton = (JButton)cb.getComponent(0);
if(arrowButton != null) {
Insets arrowInsets = arrowButton.getInsets();
buttonWidth = arrowButton.getPreferredSize().width
+ arrowInsets.left + arrowInsets.right;
arrowButton.setBounds(width - (insets.right + buttonWidth),
insets.top, buttonWidth, buttonHeight);
}
if(label != null) {
Insets labelInsets = label.getInsets();
labelWidth = label.getPreferredSize().width
+ labelInsets.left + labelInsets.right;
label.setBounds(insets.left, insets.top, labelWidth, buttonHeight);
}
JButton rssButton = button;
if(rssButton != null && rssButton.isVisible()) {
Insets loupeInsets = rssButton.getInsets();
loupeWidth = rssButton.getPreferredSize().width
+ loupeInsets.left + loupeInsets.right;
rssButton.setBounds(width - (insets.right + loupeWidth + buttonWidth),
insets.top, loupeWidth, buttonHeight);
}else{
loupeWidth = 0;
}
Component editor = cb.getEditor().getEditorComponent();
if ( editor != null ) {
editor.setBounds(insets.left + labelWidth, insets.top,
width -(insets.left+insets.right+buttonWidth+labelWidth+loupeWidth),
height-(insets.top +insets.bottom));
}
}
});
References
0 comments:
Post a Comment