将时区显示到JComboBox中

时间:2016-11-12 11:49:19

标签: java swing jcombobox

我正在尝试制作一个JComboBox,我希望获得所有时区,但不显示任何时区。有没有人可以帮我解决这个问题?

这是我的代码:

public class Window extends JFrame {
    private static final String DATE_FORMAT = "dd-M-yyyy hh:mm:ss a";
    public Window() {
        super("Genesys");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setSize(600, 470);
        setVisible(true);
        setLayout(null);
        gradeCombo = new JComboBox < Object > ();
        add(gradeCombo);
        gradeCombo.setBounds(500, 100, 200, 20);
        search.addActionListener(new csearch());
    }
    class csearch implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
            Date date = new Date();
            TimeZone tz = TimeZone.getDefault();
            pane.setBounds(10, 530, 760, 40);
            pane1.setBounds(10, 260, 760, 40);
            System.out.println("TimeZone : " + tz.getID() + " - " + tz.getDisplayName());
            System.out.println("TimeZone : " + tz);
            System.out.println("Date (Ro - UTC+02:00) : " + formatter.format(date));
            date10.setText("Current time for Romania");
            date7.setText(String.valueOf("Time Zone : " + tz.getID() + " - " + tz.getDisplayName()));
            date8.setText(String.valueOf("TimeZone : " + tz));
            date9.setText(String.valueOf("Date (Ro - UTC+02:00) : " + formatter.format(date)));
            SimpleDateFormat sdfAmerica = new SimpleDateFormat(DATE_FORMAT);
            SimpleDateFormat sdfParis = new SimpleDateFormat(DATE_FORMAT);
            DateTime dt = new DateTime(date);
            DateTimeZone dtZone = DateTimeZone.forID(country.getText());
            DateTime dtus = dt.withZone(dtZone);
            TimeZone tzInAmerica = dtZone.toTimeZone();
            Date dateInAmerica = dtus.toLocalDateTime().toDate();
            gradeCombo = new JComboBox < Object > (TimeZone.getAvailableIDs());
        }
    }
}

有人能帮帮我吗?为什么组合框中没有显示时区?

1 个答案:

答案 0 :(得分:1)

不要实例化新的JComboBox,只需将适当的模型设置为现有的组合。

class Main extends React.Component{
  render(){
    return (
      <View style={styles.mainContainer}>
        <Text> Testing the Router </Text>
      </View>
    )
  }
};