|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
JAVA学习必须明确这是一项投资,对于大多数的人来说,学习JAVA是为了就业,还有就是刚走向工作位置的朋友想尽快赶上工作的节奏。
比来进修SWING,改动JComboBox的的显现体例,这里是将JComboBox的下拉框向上显现,以下为具体代码:
package kissJava.JComboBox;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
public class PopupComboSample extends JFrame...{
String labels[] = ...{ "Chardonnay", "Sauvignon", "Riesling", "Cabernet",
"Zinfandel", "Merlot", "Pinot Noir", "Sauvignon Blanc",
"Syrah", "Gewurztraminer" };
JComboBox jcb = null;
public PopupComboSample()...{
this.setTitle("下拉框向上");
this.setLayout(null);
jcb = new JComboBox(labels);
//setUI.......
jcb.setUI((ComboBoxUI) MyComboBoxUI.createUI(jcb));
jcb.setBounds(50, 150, 200, 20);
this.add(jcb, null);
setSize(300, 300);
setVisible(true);
}
public static void main(String args[]) ...{
new PopupComboSample();
}
static class MyComboBoxUI extends BasicComboBoxUI ...{
int newsBarTitleWidth = 0;
public static ComponentUI createUI(JComponent c) ...{
return new MyComboBoxUI();
}
//改动箭头的偏向
protected JButton createArrowButton() ...{
JButton button = new BasicArrowButton(BasicArrowButton.NORTH);
return button;
}
//改动comboBox的弹出偏向
protected ComboPopup createPopup() ...{
BasicComboPopup popup = new BasicComboPopup(comboBox)...{
public void show() ...{
//巨细按必要变动
Dimension popupSize = new Dimension(200 - newsBarTitleWidth - 5, 17 * 5);
scroller.setMaximumSize(popupSize);
scroller.setPreferredSize(popupSize);
scroller.setMinimumSize(popupSize);
show(comboBox, newsBarTitleWidth, -17 * 5);//getPopupHeightForRowCount(10));
}
};
popup.getAccessibleContext().setAccessibleParent(comboBox);
return popup;
}
}
}
显现效果为:
不外看图的效果jcb的输出框没有线条显现,看来得再改改,进修中。
在性能方面,在windows平台下,.net网页编程可能是占强项,要是把.net网页编程放在sun开发的操作系统上去运行呢?根本就运行不了,.net网页编程对其它操作系统的支持也很弱,性能也可能比不上java。 |
|