简体   繁体   中英

Adjust size of JDatePicker Java Swing

I'm using JDatePicker from http://jdatepicker.org . It's cool but i cannot find any ways to change the size of the text box and the button. the setSize() only change size of the container as picture below. Any suggestions please?

在此处输入图片说明

Update: I've figured out a way that is using JFormattedTextField to point the instance of the datepicker 's textfield and resize it. The code as below:

UtilDateModel model = new UtilDateModel();
    Properties p = new Properties();
    p.put("text.today", "Today");
    p.put("text.month", "Month");
    p.put("text.year", "Year");
    JDatePanelImpl datePanel = new JDatePanelImpl(model, p);
    JDatePickerImpl dpDoB = new JDatePickerImpl(datePanel, af);
    dpDoB.setPreferredSize(new Dimension(195, 45));
    JFormattedTextField tf = dpDoB.getJFormattedTextField();
    tf.setPreferredSize(new Dimension(195, 35));
    Font font = new Font("Tahoma", 0, 16);
    tf.setFont(font);
    dpDoB.setShowYearButtons(false);
    dpDoB.setTextEditable(true);
    panelDoB.add(dpDoB);

There is still the button left unable to resize. So i'm not sure if there are any other ways to solve this

You can look for componet of JDatePickerImpl (this class have only two)

Try this:

UtilDateModel model = new UtilDateModel();
    Properties p = new Properties();
    p.put("text.today", "Today");
    p.put("text.month", "Month");
    p.put("text.year", "Year");
    JDatePanelImpl datePanel = new JDatePanelImpl(model, p);
    datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter());
    datePicker.setPreferredSize(new Dimension(120,20));
    datePicker.getComponent(0).setPreferredSize(new Dimension(100,20)); //JFormattedTextField
    datePicker.getComponent(1).setPreferredSize(new Dimension(20,20));//JButton
    add(datePicker);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM