类似于 Swing 应用程序的 Google 日历

发布于 2024-11-26 16:19:53 字数 1536 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

找个人就嫁了吧 2024-12-03 16:19:53

不是您问题的答案,但您必须构建三个视图

1/您可以将 CalendarView 的网格放入 JTable (季度/半/年 CalendarView 的最佳方法),

但其中一部分是基于使用 GridLaout/GridBagLayout(7x7) 放置到 JPanel 中的 JButton/JTextField/JLabels

最简单的方法是放置在这里JButtons,为了获得良好的输出,禁用上个月/下个月

2/WeekView 时间表的日期,使用 JTable 和一个 TableColumn,在那里放置 包含 JLabel 的 JPanel,因为某些时间表可能被渗透(或对于其他 JComponents#setOpaque(false)),

或者通过使用GridLayout(1, 7, 5, 5); with 7 x JPanel for DayViewShedule(s)

3/ for DayView with GridLayout(1, 24, 5, 5); 带有 24 个 JPanel 用于 HourShedule(s)

not an answer to your question, but you have to building three view

1/ you can put a grid for CalendarView to the JTable (best way for quarter/half/year CalendarView),

but part of them are based on JButton/JTextField/JLabels placed into JPanel with GridLaout/GridBagLayout(7x7),

easiest way is if you placed here JButtons, for nice output disable days for prevoius/next Month

2/ for WeekView shedules are used JTable with one TableColumn, there put JPanel that contains JLabel, because is possible that some shedules are penetrated (or for other JComponents#setOpaque(false)),

or by using GridLayout(1, 7, 5, 5); with 7 x JPanel for DayViewShedule(s)

3/ for DayView with GridLayout(1, 24, 5, 5); with 24 x JPanel for HourShedule(s)

Bonjour°[大白 2024-12-03 16:19:53

查看 Kai Toedter 的 JCalendar http://www.toedter.com/en/jcalendar/

Check out JCalendar by Kai Toedter http://www.toedter.com/en/jcalendar/

走过海棠暮 2024-12-03 16:19:53

我想出了一个在问题描述部分提到的映射器方法。您可以在下面找到该方法的内容。可能有更好的方法来做到这一点,但这完全满足我的需要。我利用两件事来计算 JTable 中相应的行和列索引,如下所示:

int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);


 private int[] getCalendarIndexNumbers(
            int dayOfTheMonth,
            int year,
            int month) {

        int[] retArray = new int[2];
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, dayOfTheMonth);
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);

        int rowIndex = weekOfMonth-1;
        if (rowIndex < 0) {
            rowIndex = 0;
        }

        int columnIndex;
        switch (dayOfWeek) {
            case 1:
                columnIndex = 6;
                break;
            case 2:
                columnIndex = 0;
                break;
            case 3:
                columnIndex = 1;
                break;
            case 4:
                columnIndex = 2;
                break;
            case 5:
                columnIndex = 3;
                break;
            case 6:
                columnIndex = 4;
                break;
            case 7:
                columnIndex = 5;
                break;
            default:
                columnIndex = 6;
                break;
        }

        retArray[0] = rowIndex;
        retArray[1] = columnIndex;

        return retArray;

    }

为了填充 JTable 中单元格的内容,我必须编写一个实现 TableCellRenderer 并扩展 JTextArea 的自定义渲染器。示例如下: http://archive.devx .com/java/free/articles/kabutz07/Kabutz07-2.asp

希望这可以帮助那些需要开发类似应用程序的人。

感谢您之前的回复。

此致

I came up with a mapper method that I mentioned in the problem description section. Below you can find the content of this method. There might be better ways to do this but this perfectly meets my need. I utilized two things to calculate the corresponding row and column indexes in the JTable as follows:

int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);


 private int[] getCalendarIndexNumbers(
            int dayOfTheMonth,
            int year,
            int month) {

        int[] retArray = new int[2];
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, dayOfTheMonth);
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);

        int rowIndex = weekOfMonth-1;
        if (rowIndex < 0) {
            rowIndex = 0;
        }

        int columnIndex;
        switch (dayOfWeek) {
            case 1:
                columnIndex = 6;
                break;
            case 2:
                columnIndex = 0;
                break;
            case 3:
                columnIndex = 1;
                break;
            case 4:
                columnIndex = 2;
                break;
            case 5:
                columnIndex = 3;
                break;
            case 6:
                columnIndex = 4;
                break;
            case 7:
                columnIndex = 5;
                break;
            default:
                columnIndex = 6;
                break;
        }

        retArray[0] = rowIndex;
        retArray[1] = columnIndex;

        return retArray;

    }

In order to fill the contents of the cells in the JTable, I had to write a custom renderer that implements TableCellRenderer and extends JTextArea. An example for this is available at: http://archive.devx.com/java/free/articles/kabutz07/Kabutz07-2.asp

Hope this helps those who needs to develop a similar application.

Thanks for the previous responses.

Best Regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文