为什么这个选择下拉框不跳转其他日历JPanel panel2 = new JPanel();panel2.setLayout(new GridLayout(7,7));7*7的网格 panel2.add(new JLabel(“一”,SwingConstants.CENTER));panel2.add(new JLabel(“二”,SwingConstants.CENTER));panel2.add(new JLabel(“三”,SwingConstants.CENTER));panel2.add(new JLabel(“四”,SwingConstants.CENTER));panel2.add(new JLabel(“五”,SwingConstants.CENTER));panel2.add(new JLabel(“六”,SwingConstants.CENTER));panel2.add(new JLabel(“日”,SwingConstants.CENTER));int year = comboBoxYear.getSelectedIndex();int month = comboBoxMonth.getSelectedIndex();日历第一个月份的一天 = 日历.getInstance();firstDayOfMonth.set(year,month-1,1);int firstDayOfWeek = firstDayOfMonth.get(Calendar.DAY_OF_WEEK)-1;int numOfMonth = firstDayOfMonth.getActualMaximum(Calendar.DAY_OF_MONTH);整数 k,num = 1;字符串编号;for(k = 0;k < 42;k++){ if(k < firstDayOfWeek - 2||k >= firstDayOfWeek + numOfMonth-2){ panel2.add(new JLabel(“”,SwingConstants.CENTER)); }else{ number = String.valueOf(num); panel2.add(new JLabel(number,SwingConstants.CENTER)); num++; } }ActionListener listener = e -> { int year1 = comboBoxYear.getSelectedIndex(); int month1 = comboBoxMonth.getSelectedIndex();Calendar firstDayOfMonth1 = Calendar.getInstance();首日1.集(年1,月1-1,1);int firstDayOfWeek1 = firstDayOfMonth1.get(Calendar.DAY_OF_WEEK)-1;int numOfMonth1 = firstDayOfMonth1.getActualMaximum(Calendar.DAY_OF_MONTH);整数 k1, 数字 1 = 1;字符串编号 1;for(k1 = 0; k1 < 42; k1++){ if(k1 < firstDayOfWeek1 - 2|| k1 >= firstDayOfWeek1 + numOfMonth1 -2){ panel2.add(new JLabel(“”,SwingConstants.CENTER)); }else{ number1 = String.valueOf(num1); panel2.add(new JLabel(number1,SwingConstants.CENTER)); num1++; } }};comboBoxYear.addActionListener(listener);comboBoxMonth.addActionListener(listener);
时间: 2024-01-24 14:18:58 浏览: 72
Select2.js下拉框使用小结
可能是因为你没有将这个选择下拉框与其他日历JPanel进行关联。你需要在监听器中添加代码来更新其他日历JPanel的显示内容。具体来说,当选择下拉框的值发生变化时,你需要重新计算该月份的第一天是星期几以及该月份有多少天,然后更新其他日历JPanel的显示内容。你可以通过遍历JPanel中的所有标签来实现更新。
阅读全文