大家好好读这个。 我目前正在开发一个程序,它应该以不同的分辨率运行良好,因此具有缩放因子。
有一个组件,我无法找到缩放的解决方案: JXDatePicker及其JXMonthView。 我尝试了什么:
final JXDatePicker datePicker = new JXDatePicker(new Date());
final JXMonthView monthView = datePicker.getMonthView();
monthView.setBounds(hauptFrame.getSize().width / 2 - (100*ViewerDefaults.SZ_INCR), (165*ViewerDefaults.SZ_INCR), (200*ViewerDefaults.SZ_INCR), (200*ViewerDefaults.SZ_INCR));
monthView.setSize(monthView.getWidth() * ViewerDefaults.SZ_INCR, monthView.getHeight() * ViewerDefaults.SZ_INCR);
monthView.setPreferredColumnCount(1);
monthView.setPreferredRowCount(1);
monthView.setTraversable(true);
monthView.setZoomable(true);
datePicker.setSize(datePicker.getWidth() * 2, datePicker.getHeight() * 2);
ViewerDefaults.SZ_INCR是缩放因子,如果正常工作,将替换最后一行中的2。
我添加了setPreferredColumnCount(1)和setPreferredRowCount(1),因为我之前尝试过设置JXMonthview的大小,但我最终有4个月显示在彼此旁边,而我只想要一个更大的显示月份。
你能帮忙并告诉我一种只在月份放大显示的方法吗?
编辑: 我将所有内容翻译成使用布局管理器。问题仍然存在:显示的月份未按比例放大,而只是显示在中心。为了更深入地了解代码,我将整个方法放在这里如下(大小由Toolkit.getDefaultToolkit()提前设置.getScreenSize();):
private static JPanel licBorrowPanel = null;
licBorrowPanel = new JPanel();
licBorrowPanel.setBounds(0, 20, size.width, size.height-20);
licBorrowPanel.setVisible(false);
licBorrowPanel.setBackground(Color.WHITE);
public static void licenceBorrowDialog() {
licBorrowPanel.setSize(new Dimension(hauptFrame.getSize().width, hauptFrame.getSize().height));
licBorrowPanel.setBackground(Color.WHITE);
licBorrowPanel.setLayout(new BorderLayout());
licBorrowPanel.setVisible(true);
//Create upper part of licBorrowPanel
JPanel licBorrowTop = new JPanel();
licBorrowTop.setLayout(new BoxLayout(licBorrowTop, BoxLayout.Y_AXIS));
// Label Titel
JLabel labelTitel = new JLabel("License borrwing");
labelTitel.setHorizontalAlignment(JLabel.CENTER);
labelTitel.setFont(ViewerDefaults.DEF_LABEL_FONT);
licBorrowTop.add(labelTitel);
// Header Calendar
JLabel calendarTitle = new JLabel("Please select a date", SwingConstants.LEFT);
calendarTitle.setHorizontalAlignment(JLabel.CENTER);
calendarTitle.setFont(ViewerDefaults.DEF_ROW_FONT);
licBorrowTop.add(calendarTitle);
licBorrowPanel.add(licBorrowTop, BorderLayout.PAGE_START);
//Create central part of licBorrowPanel
JPanel licBorrowCenter = new JPanel();
licBorrowCenter.setLayout(new BoxLayout(licBorrowCenter, BoxLayout.Y_AXIS));
// Label selectedDate
final JLabel labelSelectedDate = new JLabel("<HTML><BODY> </HTML></BODY>");
labelSelectedDate.setHorizontalAlignment(JLabel.CENTER);
labelSelectedDate.setFont(ViewerDefaults.DEF_LIC_FONT);
labelSelectedDate.setText("<HTML><BODY><b>Some Text</HTML></BODY>");
// Calendar
final JXDatePicker datePicker = new JXDatePicker(new Date());
final JXMonthView monthView = datePicker.getMonthView();
monthView.setPreferredColumnCount(1);
monthView.setPreferredRowCount(1);
monthView.setZoomable(true); //Removing this results in several Columns and Rows being displayed.
// Set selection to "in two days" as default
Date newDate = monthView.getSelectionDate();
newDate.setDate(newDate.getDate()+2);
datePicker.addActionListener(new ActionListener() {
//...
});
licBorrowCenter.add(monthView, BorderLayout.CENTER);
licBorrowCenter.add(labelSelectedDate, BorderLayout.CENTER);
// Footer Calendar
JLabel calendarSubTitle = new JLabel("<HTML><BODY><CENTER>Some other Text.</CENTER></HTML></BODY>", SwingConstants.LEFT);
calendarSubTitle.setFont(ViewerDefaults.DEF_FONT);
calendarSubTitle.setHorizontalAlignment(JLabel.CENTER);
calendarSubTitle.setFont(ViewerDefaults.DEF_ROW_FONT);
calendarSubTitle.setForeground(Color.RED);
licBorrowCenter.add(calendarSubTitle, BorderLayout.CENTER);
licBorrowPanel.add(licBorrowCenter);
//Create lower part of licBorrowPanel
JPanel licBorrowBottom = new JPanel();
licBorrowBottom.setLayout(new BorderLayout());
// Button OK
JButton buttonLicBorrowOK = new JButton("OK");
buttonLicBorrowOK.setFont(ViewerDefaults.DEF_LIC_FONT);
licBorrowBottom.add(buttonLicBorrowOK, BorderLayout.LINE_START);
// Button Return
JButton buttonLicReturn = new JButton("Return");
buttonLicReturn.setFont(ViewerDefaults.DEF_LIC_FONT);
licBorrowBottom.add(buttonLicReturn, BorderLayout.CENTER);
// Button Cancel
JButton buttonLicBorrowCancel = new JButton("Cancel");
buttonLicBorrowCancel.setFont(ViewerDefaults.DEF_LIC_FONT);
licBorrowBottom.add(buttonLicBorrowCancel, BorderLayout.LINE_END);
licBorrowPanel.add(licBorrowBottom, BorderLayout.PAGE_END);
// Update licBorrowPanel
licBorrowPanel.update(licBorrowPanel.getGraphics());
// several action listeners for buttons eluded..
}
“hauptframe”是父JFrame。 发生了另一个问题,但我认为一旦JXMonthView显示为需要,这将解决:不显示licBorrowBottom。
我希望这可以澄清问题,并帮助帮助:)