Last active
December 29, 2015 01:19
-
-
Save ayapi/7592669 to your computer and use it in GitHub Desktop.
JXDatePickerで選択できる日付の範囲を限定する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.lang3.time.DateFormatUtils; | |
import org.apache.commons.lang3.time.DateUtils; | |
import org.jdesktop.swingx.JXDatePicker; | |
import javax.swing.*; | |
import java.awt.*; | |
import java.util.Date; | |
import java.util.TimeZone; | |
public class Calendar extends JPanel { | |
private JXDatePicker datePicker; | |
public Calendar(){ | |
initDatePicker(); | |
} | |
private void initDatePicker(){ | |
Date tomorrow = DateUtils.addDays(new Date(), 1); | |
Date oneWeekAfter = DateUtils.addDays(new Date(), 7); | |
datePicker = new JXDatePicker(tomorrow); | |
datePicker.getMonthView().setLowerBound(tomorrow); | |
datePicker.getMonthView().setUpperBound(oneWeekAfter); | |
UIManager.put("JXMonthView.unselectableDayForeground", Color.GRAY); | |
add(datePicker); | |
} | |
public String getDate() { | |
return DateFormatUtils.format( | |
datePicker.getDate(), | |
"yyyy-MM-dd", | |
TimeZone.getTimeZone("GMT") | |
); | |
} | |
} | |
class Window { | |
public static void main(String[] args) throws Exception { | |
JFrame frame = new JFrame(); | |
frame.setSize(200, 200); | |
Calendar calendar = new Calendar(); | |
frame.add(calendar); | |
SwingUtilities.updateComponentTreeUI(frame); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment