Im pretty new to Java (and programming). Trying to figure out how to make Jpanel sizes relative to the JFrame size. I'm just trying to create a calendar and I have three different panels: one for the month title; one for the days of the week; and another for the calendar body.
Here's my code:
public DisplayACalendar() { setLayout(new GridLayout(3, 1)); // create JPanel for month/year JPanel monthTitle = new JPanel(); monthTitle.add(new JLabel(month + " " + year)); // create JPanel for Days of Week String[] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; JPanel daysOfWeekPanel = new JPanel(new GridLayout(1, 7)); for (int i = 0; i < 7; i++) { daysOfWeekPanel.add(new JLabel(days[i])); } // Create JPanel for calendar dates JPanel calendarMonth = new JPanel(new GridLayout(6, 7)); for (int i = 1; i < firstDay; i++) calendarMonth.add(new JLabel()); for (int i = 1; i <= daysInMonth; i++) { JLabel jlblDayCell = new DayCell(i); jlblDayCell.setHorizontalAlignment(JLabel.RIGHT); calendarMonth.add(jlblDayCell); } int daysLeft = 42 - daysInMonth - firstDay; for (int i = 0; i < daysLeft; i++) calendarMonth.add(new JLabel()); add(monthTitle); add(daysOfWeekPanel); add(calendarMonth); } And here's the Result:

(source: staticflickr.com)
How do I fix this? For example, let's say I want to make the body panel 80% of the frame and the other two 10% each.