Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / swing / JComboBox.java
1 package javajs.swing;
2
3 import javajs.util.SB;
4
5 public class JComboBox<T>  extends AbstractButton {
6
7         private String[] info;
8         private int selectedIndex;
9
10         public JComboBox(String[] info){
11                 super("cmbJCB");
12                 this.info = info;
13         }
14
15         public void setSelectedIndex(int i) {
16                 selectedIndex = i;
17                 /**
18                  * @j2sNative
19                  * 
20                  * SwingController.setSelectedIndex(this);
21                  * 
22                  */
23                 {
24                 }
25         }
26
27         public int getSelectedIndex() {
28                 return selectedIndex;
29         }
30
31         public Object getSelectedItem() {
32                 return (selectedIndex < 0 ? null : info[selectedIndex]);
33         }
34
35         @Override
36         public String toHTML() {
37                 SB sb = new SB();
38                 sb.append("\n<select id='" + id + "' class='JComboBox' onchange='SwingController.click(this)'>\n");             
39                 for (int i = 0; i < info.length; i++)
40                         sb.append("\n<option class='JComboBox_option'" + (i == selectedIndex ? "selected":"") + ">" + info[i] + "</option>");
41                 sb.append("\n</select>\n");
42                 return sb.toString();
43         }
44
45
46
47 }