java下拉框怎么写

1. 我想用JAVA语句来实现一个表格下拉框,代码怎么写 /*DefaultTable.java*/import javax.swing.table.AbstractTableModel;public class DefaultTable extends AbstractTableModel{ private static final long serialVersionUID = 1L; private String[] titles={"姓名","年龄","性别","数学成绩","英文成绩","总分","是否及格"}; private Object[][] userInfo={{"李星华",30,"男",89,97,186,true},{"李康",23,"女",90,93,183,false}, {"庄康健",25,"男",80,90,170,false}}; public int getRowCount() { return userInfo.length; } public int getColumnCount() { return titles.length; } public Object getValueAt(int rowIndex, int columnIndex) { return userInfo[rowIndex][columnIndex]; } public String getColumnName(int columnIndex){ return titles[columnIndex]; } public Class> getColumnClass(int columnIndex){ return this.getValueAt(0, columnIndex).getClass(); } public boolean isCellEditable(int rowIndex, int columnIndex){ return true; } public void setValueAt(Object newValue,int rowIndex, int columnIndex){ this.userInfo[rowIndex][columnIndex]=newValue; }}/*TableColumnMode.java*/import java.awt.BorderLayout;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.DefaultCellEditor;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;public class TableColumnMode { private JFrame frame=new JFrame("表格窗口"); private JTable table=null; private DefaultTable defaultTable=new DefaultTable(); private JComboBox box=new JComboBox(); public TableColumnMode(){ table=new JTable(defaultTable); box.addItem("男"); box.addItem("女"); table.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(box)); JScrollPane scr=new JScrollPane(table); JPanel pan=new JPanel(); frame.add(pan,BorderLayout.NORTH); frame.add(scr,BorderLayout.CENTER); frame.setSize(370, 160); frame.setLocation(550,100); frame.setVisible(true); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent arg0){ System.exit(1); } }); } public static void main(String[] args) { new TableColumnMode(); }} 。
2. java swing里年份下拉框怎么写 this.jcombobox1.getselecteditem();
如果要让jtextfield1的值随jcombobox1的选择变化,则在event事件中选择“itemstatechanged” 。jbuilder自动生成public void jcombobox1_itemstatechanged(itemevent e) {}后在该方法内添加代码格式如下:
public void jcombobox1_itemstatechanged(itemevent e) {
this.jtextfield1.settext("");
【java下拉框怎么写】this.jtextfield1.settext(this.jcombobox1.getselecteditem().tostring());
}
//以下是jbuilder自动生成的事件监听器
class frame1_jcombobox1_itemadapter implements itemlistener {
private frame1 adaptee;
frame1_jcombobox1_itemadapter(frame1 adaptee) {
this.adaptee = adaptee;
}
public void itemstatechanged(itemevent e) {
adaptee.jcombobox1_itemstatechanged(e);
}
}
3. 怎样添加JAVA 下拉框 Choice choice=new Choice();
choice.add(你要显示的字符串);
然后将choice添加到你的容器里
//然后添加监听器
choice.addItemListener(this);
下面写方法
public void itemStateChanged(ItemEvent e){
String name=choice.getSelectedItem();
//或者 int index=choice.getSelectedIndex();
//剩下的方法体自己根据需求写了
}
4. Java中关于下拉列表框 参见:
转到:第
<select id="P_Page" onchange="location.href='http://www.xuexi88.com/zhishi/newslist.jsp?cp='+this.options[this.selectedIndex].value+'&gp=<%=newsGroup %>'">
<%
for(int i=1;i<=totalPageCount;i++)
{
if(i==currentPage)
{
%>
<option value="http://www.xuexi88.com/zhishi/" selected><%=i %></option>
<%
}else{
%>
<option value="http://www.xuexi88.com/zhishi/"><%=i %></option>