Welcome to Dream.In.Code
Become a Java Expert!

Join 149,484 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,382 people online right now. Registration is fast and FREE... Join Now!




JTable help

 
Reply to this topicStart new topic

JTable help

HermanW
15 May, 2007 - 04:04 PM
Post #1

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
Hi just wondering if anyone can help me with this code

CODE

import javax.swing.*;
import java.awt.*;

public class TableTest extends JFrame
{
    public TableTest()
    {
        String[] columnNames =
        {
            "Time / Comp No.",
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
        };
                                
        Object[][] data =
        {
            {"8:00", "", "", "", "", "", "", "", "", "", ""},
            {"8:15", "", "", "", "", "", "", "", "", "", ""},
            {"8:30", "", "", "", "", "", "", "", "", "", ""},
            {"8:45", "", "", "", "", "", "", "", "", "", ""},
            {"9:00", "", "", "", "", "", "", "", "", "", ""},
            {"9:15", "", "", "", "", "", "", "", "", "", ""},
            {"9:30", "", "", "", "", "", "", "", "", "", ""},
            {"9:45", "", "", "", "", "", "", "", "", "", ""},
            {"10:00", "", "", "", "", "", "", "", "", "", ""},
            {"10:15", "", "", "", "", "", "", "", "", "", ""},
            {"10:30", "", "", "", "", "", "", "", "", "", ""},
            {"10:45", "", "", "", "", "", "", "", "", "", ""},
            {"11:00", "", "", "", "", "", "", "", "", "", ""},
            {"11:15", "", "", "", "", "", "", "", "", "", ""},
            {"11:30", "", "", "", "", "", "", "", "", "", ""},
            {"11:45", "", "", "", "", "", "", "", "", "", ""},
            {"12:00", "", "", "", "", "", "", "", "", "", ""},
            {"12:15", "", "", "", "", "", "", "", "", "", ""},
            {"12:30", "", "", "", "", "", "", "", "", "", ""},
            {"12:45", "", "", "", "", "", "", "", "", "", ""},
            {"13:00", "", "", "", "", "", "", "", "", "", ""},
            {"13:15", "", "", "", "", "", "", "", "", "", ""},
            {"13:30", "", "", "", "", "", "", "", "", "", ""},
            {"13:45", "", "", "", "", "", "", "", "", "", ""},
            {"14:00", "", "", "", "", "", "", "", "", "", ""},
            {"14:15", "", "", "", "", "", "", "", "", "", ""},
            {"14:30", "", "", "", "", "", "", "", "", "", ""},
            {"14:45", "", "", "", "", "", "", "", "", "", ""},
            {"15:00", "", "", "", "", "", "", "", "", "", ""},
            {"15:15", "", "", "", "", "", "", "", "", "", ""},
            {"15:30", "", "", "", "", "", "", "", "", "", ""},
            {"15:45", "", "", "", "", "", "", "", "", "", ""},
            {"16:00", "", "", "", "", "", "", "", "", "", ""},
            {"16:15", "", "", "", "", "", "", "", "", "", ""},
            {"16:30", "", "", "", "", "", "", "", "", "", ""},
            {"16:45", "", "", "", "", "", "", "", "", "", ""},
            {"17:00", "", "", "", "", "", "", "", "", "", ""},
            {"17:15", "", "", "", "", "", "", "", "", "", ""},
            {"17:30", "", "", "", "", "", "", "", "", "", ""},
            {"17:45", "", "", "", "", "", "", "", "", "", ""},
            {"18:00", "", "", "", "", "", "", "", "", "", ""},
            {"18:15", "", "", "", "", "", "", "", "", "", ""},
            {"18:30", "", "", "", "", "", "", "", "", "", ""},
            {"18:45", "", "", "", "", "", "", "", "", "", ""},
            {"19:00", "", "", "", "", "", "", "", "", "", ""},
            {"19:15", "", "", "", "", "", "", "", "", "", ""},
            {"19:30", "", "", "", "", "", "", "", "", "", ""},
            {"19:45", "", "", "", "", "", "", "", "", "", ""},
            {"20:00", "", "", "", "", "", "", "", "", "", ""}
         };
        
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BorderLayout());
        getContentPane().add(contentPanel);
        
        JTable table = new JTable(data, columnNames);
                
        JScrollPane scrollPane = new JScrollPane( table );
        contentPanel.add( scrollPane, BorderLayout.CENTER );
    }
    
    public static void main (String[] args)
    {
        TableTest TT = new TableTest();
        TT.setVisible( true );
    }


As you can see from the code, I'm trying to implement a table (which i've done) but I'm trying to make the cells UNEDITABLE. How can I do that?

Also is there anyway of creating the time easier like in a for loop? It needs to start from 8am to 8pm and in 15min intervals.
User is offlineProfile CardPM
+Quote Post

1lacca
RE: JTable Help
15 May, 2007 - 11:29 PM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
If a cell is editable depends on the TableModel. The easiest way to create a Table with uneditable cells is to subclass the javax.swing.table.DefaultTableModel class and override the boolean isCellEditable(int row, int column) function, so it returns false all the time. Then when you are creating your table, creaet it with this new model.

Yes, you can create the time in a for loop, but you'll have to use the new operator.


User is offlineProfile CardPM
+Quote Post

HermanW
RE: JTable Help
26 May, 2007 - 12:23 PM
Post #3

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
I didn't quite get the reply but thnx for the reply anyway... Anyway this is what my program looks like so far and kinda need help improving the table...

CODE

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ScheduleWindow extends JFrame implements ActionListener
{    
    String[] dates = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11","12", "13", "14", "15", "16",
                      "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
    String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    String[] years = {"2007", "2008"};
    
    Object[][] rowNames  =
    {
        {"0800", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0815", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0830", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0845", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0900", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0915", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0930", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0945", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1000", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1015", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1030", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1045", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1100", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1115", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1130", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1145", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1200", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1215", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1230", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1245", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1300", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1315", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1330", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1345", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1400", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1415", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1430", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1445", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1500", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1515", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1530", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1545", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1600", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1615", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1630", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1645", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1700", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1715", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1730", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1745", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1800", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1815", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1830", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1845", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1900", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1915", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1930", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1945", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"2000", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
    };
    
    String[] colNames = {"Time / Num", "PC 01", "PC 02", "PC 03", "PC 04", "PC 05", "PC 06", "PC 07", "PC 08", "PC 09", "PC 10", "PC 11", "PC 12",
                         "PC 13", "PC 14", "PC 15", "PC 16", "PC 17", "PC 18", "PC 19", "PC 20", "PC 21", "PC 22", "PC 23", "PC 24", "PC 25"};

    // init Row 1
    JPanel row1 = new JPanel();
    JLabel TitleLabel = new JLabel("Adult Learning Centre Booking System", JLabel.CENTER);
    
    // init Row 2
    JPanel row2 = new JPanel();
    JTable table = new JTable(rowNames, colNames);
    JScrollPane scroll = new JScrollPane(table);
    
    // init Row 3
    JPanel row3 = new JPanel();
    JComboBox cmbDays = new JComboBox();
    JComboBox cmbMonths = new JComboBox();
    JComboBox cmbYears = new JComboBox();
    JButton btnGo = new JButton("Go");
    
    // init Row 4
    JPanel row4 = new JPanel();
    JButton btnBook = new JButton("Book");
    JButton btnPersonal = new JButton("Timetable");
    JButton btnLogout = new JButton("Logout");
    
    public ScheduleWindow()
    {
        super("Booking System Ver.2");
        setSize(850, 600);
        setResizable(false);
        setLocation(300, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        BorderLayout layout = new BorderLayout();
        Container pane = getContentPane();
        pane.setLayout(layout);
        
        FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER, 10, 10);
        row1.setLayout(layout1);
        row1.add(TitleLabel);
        pane.add(row1, BorderLayout.PAGE_START);
        
        FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 10, 10);
        row2.setLayout(layout2);
        row2.add(scroll);
        
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        
        row2.setBorder(BorderFactory.createTitledBorder("Schedule"));
        pane.add(row2, BorderLayout.CENTER);
        
        FlowLayout layout3 = new FlowLayout(FlowLayout.RIGHT, 10, 10);
        row3.setLayout(layout3);
        row3.add(cmbDays);
        row3.add(cmbMonths);
        row3.add(cmbYears);
        row3.add(btnGo);
        
        row3.setBorder(BorderFactory.createTitledBorder("Date Selection"));
        pane.add(row3, BorderLayout.PAGE_END);

        GridLayout layout4 = new GridLayout(3, 1, 50, 50);
        row4.setLayout(layout4);
        row4.add(btnBook);
        row4.add(btnPersonal);
        row4.add(btnLogout);
        
        row4.setBorder(BorderFactory.createTitledBorder("User Selection"));
        pane.add(row4, BorderLayout.LINE_END);

        setContentPane(pane);
        setVisible(true);
    }
    
    public void actionPerformed(ActionEvent e)
    {
        
    }
}


What it looks like (pls check the pic). So the problem i have is just to improve the width of each col and make the whole table uneditable... any suggestions?


This post has been edited by HermanW: 26 May, 2007 - 12:30 PM


Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

HermanW
RE: JTable Help
26 May, 2007 - 01:17 PM
Post #4

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
Actually managed to make the table un-editable but the code to fix the col width didn't work... what did i do wrong?

CODE

import java.io.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;

public class ScheduleWindow extends JFrame implements ActionListener
{    
    String[] dates = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11","12", "13", "14", "15", "16",
                      "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
    String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    String[] years = {"2007", "2008"};
    
    Object[][] rowNames  =
    {
        {"0800", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0815", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0830", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0845", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0900", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0915", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0930", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"0945", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1000", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1015", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1030", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1045", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1100", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1115", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1130", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1145", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1200", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1215", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1230", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1245", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1300", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1315", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1330", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1345", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1400", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1415", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1430", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1445", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1500", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1515", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1530", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1545", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1600", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1615", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1630", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1645", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1700", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1715", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1730", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1745", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1800", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1815", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1830", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1845", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1900", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1915", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1930", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"1945", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""},
        {"2000", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
    };
    
    String[] colNames = {"Time / Num", "PC 01", "PC 02", "PC 03", "PC 04", "PC 05", "PC 06", "PC 07", "PC 08", "PC 09", "PC 10", "PC 11", "PC 12",
                         "PC 13", "PC 14", "PC 15", "PC 16", "PC 17", "PC 18", "PC 19", "PC 20", "PC 21", "PC 22", "PC 23", "PC 24", "PC 25"};

    // init Row 1
    JPanel row1 = new JPanel();
    JLabel TitleLabel = new JLabel("Adult Learning Centre Booking System", JLabel.CENTER);
    
    // init Row 2
    JPanel row2 = new JPanel();
    Table table = new JTable(rowNames, colNames)
    {
        public boolean isCellEditable(int rowIndex, int vColIndex)
        {
            return false;
        }    
    };    
    JScrollPane scroll = new JScrollPane(table);
    
    // init Row 3
    JPanel row3 = new JPanel();
    JComboBox cmbDays = new JComboBox(dates);
    JComboBox cmbMonths = new JComboBox(months);
    JComboBox cmbYears = new JComboBox(years);
    JButton btnGo = new JButton("Go");
    
    // init Row 4
    JPanel row4 = new JPanel();
    JButton btnBook = new JButton("Book");
    JButton btnPersonal = new JButton("Timetable");
    JButton btnLogout = new JButton("Logout");
    
    public ScheduleWindow()
    {
        super("Booking System Ver.2");
        setSize(850, 600);
        setResizable(false);
        setLocation(200, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        BorderLayout layout = new BorderLayout();
        Container pane = getContentPane();
        pane.setLayout(layout);
        
        FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER, 10, 10);
        row1.setLayout(layout1);
        row1.add(TitleLabel);
        pane.add(row1, BorderLayout.PAGE_START);
        
        FlowLayout layout2 = new FlowLayout(FlowLayout.CENTER, 10, 10);
        row2.setLayout(layout2);
        row2.add(scroll);
        
        TableColumn column = null;
        
        for (int i = 0; i < 26; i++)
        {
            column = table.getColumnModel().getColumn(i);
            column.setPreferredWidth(450);
        }
        
        for(int rows = 0; rows < 49; rows++)
        {
            for(int cols = 0; cols < 26; cols++)
            {
                table.isCellEditable(rows, cols);
            }
        }
                        
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        
        row2.setBorder(BorderFactory.createTitledBorder("Schedule"));
        pane.add(row2, BorderLayout.CENTER);
        
        FlowLayout layout3 = new FlowLayout(FlowLayout.RIGHT, 10, 10);
        row3.setLayout(layout3);
        row3.add(cmbDays);
        row3.add(cmbMonths);
        row3.add(cmbYears);
        row3.add(btnGo);
        
        row3.setBorder(BorderFactory.createTitledBorder("Date Selection"));
        pane.add(row3, BorderLayout.PAGE_END);

        GridLayout layout4 = new GridLayout(3, 1, 50, 50);
        row4.setLayout(layout4);
        row4.add(btnBook);
        row4.add(btnPersonal);
        row4.add(btnLogout);
        
        row4.setBorder(BorderFactory.createTitledBorder("User Selection"));
        pane.add(row4, BorderLayout.LINE_END);

        setContentPane(pane);
        setVisible(true);
    }
    
    public void actionPerformed(ActionEvent e)
    {
        
    }
}




This post has been edited by HermanW: 26 May, 2007 - 01:19 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:42PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month