java 显示日历 swing_Java Swing 日历 控件

/***

* Copyright: Ares.

* All Rights Reserved.

* Company: Insigma HT/上海创图

*@authorAres

private static Color hoverColor = Color.BLUE; //hover color

private Chooser(java.util.Date date, String format, intstartDAY){if(startDAY > -1 && startDAY < 7) defaultStartDAY =startDAY;int dayIndex =defaultStartDAY;for(int i=0; i<7; i++){if(dayIndex > 6) dayIndex = 0;

weekLabels[i]= newWeekLabel(dayIndex, showTEXT[dayIndex]);

dayIndex++;

}

sdf= newjava.text.SimpleDateFormat(format);

calendar=Calendar.getInstance();

calendar.setTime(date);

initCalendarPanel();

}public staticChooser getInstance(java.util.Date date, String format){return newChooser(date, format, defaultStartDAY);

}public staticChooser getInstance(java.util.Date date){returngetInstance(date, DEFAULTFORMAT);

}public staticChooser getInstance(String format){return getInstance(newjava.util.Date(), format);

}public staticChooser getInstance(){return getInstance(newjava.util.Date(), DEFAULTFORMAT);

}private voidinitCalendarPanel(){

calendarPanel= new JPanel(newjava.awt.BorderLayout());

calendarPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0xAA, 0xAA, 0xAA)));

calendarPanel.add(titlePanel= newTitlePanel(), java.awt.BorderLayout.NORTH);

calendarPanel.add(bodyPanel= newBodyPanel(), java.awt.BorderLayout.CENTER);

calendarPanel.add(footerPanel= newFooterPanel(),java.awt.BorderLayout.SOUTH);this.addAncestorListener(newAncestorListener() {public voidancestorAdded(AncestorEvent event) { }public voidancestorRemoved(AncestorEvent event) {hidePanel();}//hide pop when move component.

public voidancestorMoved(AncestorEvent event) {

hidePanel();

}

});

}public void register(finalJComponent showComponent) {this.showDate =showComponent;

showComponent.setRequestFocusEnabled(true);

showComponent.addMouseListener(newMouseAdapter() {public voidmousePressed(MouseEvent me) {

showComponent.requestFocusInWindow();

}

});this.add(showComponent, BorderLayout.CENTER);this.setPreferredSize(new Dimension(90, 25));this.setBorder(BorderFactory.createLineBorder(Color.GRAY));

showComponent.addMouseListener(newMouseAdapter() {public voidmouseEntered(MouseEvent me) {if(showComponent.isEnabled()) {

showComponent.setCursor(newCursor(Cursor.HAND_CURSOR));

}

}public voidmouseExited(MouseEvent me) {if(showComponent.isEnabled()) {

showComponent.setCursor(newCursor(Cursor.DEFAULT_CURSOR));

showComponent.setForeground(Color.BLACK);

}

}public voidmousePressed(MouseEvent me) {if(showComponent.isEnabled()) {

showComponent.setForeground(hoverColor);if(isShow) {

hidePanel();

}else{

showPanel(showComponent);

}

}

}public voidmouseReleased(MouseEvent me) {if(showComponent.isEnabled()) {

showComponent.setForeground(Color.BLACK);

}

}

});

showComponent.addFocusListener(newFocusListener() {public voidfocusLost(FocusEvent e) {

hidePanel();

}public voidfocusGained(FocusEvent e) { }

});

}//hide the main panel.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值