Solved

Create a schedule

Posted on 2004-04-27
28
908 Views
Last Modified: 2008-02-01
i need to create a schedule  of appointments using java
the rows heading of the table signify the day while the columns heading are used for time
the user can also have the option of merging multiple rows for a given day to create an appointment that extend for multiple hours

i need this urgently
0
Comment
Question by:razo
  • 14
  • 12
  • +1
28 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 10927501
you want us to write the whole thing?

We can't do your homework for you...

Do you have a specific problem?
0
 
LVL 8

Author Comment

by:razo
ID: 10927558
first it is not a homework
second i only need an outline like to use for the schedule; does JTable works for that?
 and how i can i merge cells
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10927676
>> does JTable works for that?
Yeah, why not.

>> how i can i merge cells
You can't. But why should you?
You can change the background color to indicate an appointment that extends for multiple hours.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 10928709
Hello zzny, the java JTable has only a basic functinality. There are several other grid controls (see www.dundas.com or http://www.quest.com/jclass/index.asp) wich provide an enhance functionality. (Sorry they are not free)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10928776
>> Hello zzny
Are you talking to me?

>>the java JTable has only a basic functinality
Which is enough for what the user asks.
Look to Outlook's Calender: No merging of cells when indicating appointements of more than one hour.
0
 
LVL 8

Author Comment

by:razo
ID: 10936283
i examined JTable yesterday and i couldn't find a way to put row headings
as for merging cells it is not necessary to merge but i want to give the user to be able to add an appointments thru the grid to extend for multiple hours...it is not only for view
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10936389
>> i want to give the user to be able to add an appointments thru the grid to extend for multiple hours
That can be done by selecting multiple cells (for one row/day)

>>i examined JTable yesterday and i couldn't find a way to put row headings
Did you put your table in a JScrollPane?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10936717
>> That can be done by selecting multiple cells.
Play around with this *very simple* example. Hopefully it gives you ideas.

/*
 * TableDemo.java
 *
 */

import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
/**
 *
 */
public class TableDemo extends javax.swing.JFrame {

    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable theTable;
   
    /** Creates new form TableDemo */
    public TableDemo() {
        initComponents();
        initTable();
    }
   
    private void initTable() {
        theTable.setModel(new MyOwnTableModel());
        theTable.setCellSelectionEnabled(true);
    }
   
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        theTable = new javax.swing.JTable();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jScrollPane1.setViewportView(theTable);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pack();
    }
   
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
   
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
            System.exit(0);
        }
       
        new TableDemo().show();
    }
   
    public class MyOwnTableModel extends DefaultTableModel {
   
        final String[] columnNames = { "Day",
                                       "08:00-08:15", "08:15-08:30",
                                       "08:30-08:45", "08:45-09:00" };
                                       
        private Object data[][] = {
                {"Monday", " ", " ", " ", " "},
                {"Tuesday", " ", " ", " ", " "},
                {"Wednesday", " ", " ", " ", " "},
                {"Thursday", " ", " ", " ", " "},
                {"Friday", " ", " ", " ", " "},
                {"Saturday", " ", " ", " ", " "},
                {"Sunday", " ", " ", " ", " "},
        };
       
        public MyOwnTableModel() {
        }
        public boolean isCellEditable(int row, int col) { return false; }
        public Class getColumnClass(int col) {
            return super.getColumnClass(col);
        }        
        public int getRowCount() { return 7; }
        public int getColumnCount() { return 5; }
        public String getColumnName(int col) {
            return columnNames[col];
        }
        public Object getValueAt(int row, int col) {
            return data[row][col];
        }
     }
}
0
 
LVL 8

Author Comment

by:razo
ID: 10936760
ok that is exactly what i need but please i dont have time to research mutiple selection
please can u explain how can i do multiple selection and how can i allow the user to do that at run-time when adding data
thanks
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10936866
Replace initTable() by this extended version.
And see the tracing when selecting multiple rows/columns.


    private void initTable() {
        theTable.setModel(new MyOwnTableModel());
        theTable.setCellSelectionEnabled(true);
        theTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        ListSelectionModel rowSM = theTable.getSelectionModel();
        rowSM.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;
                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        System.out.println("No rows are selected.");
                    } else {
                        int selectedRowFrom = lsm.getMinSelectionIndex();
                        int selectedRowTo = lsm.getMaxSelectionIndex();
                        if (selectedRowTo==selectedRowFrom)
                            System.out.println("Row " + selectedRowFrom
                                           + " is now selected.");
                        else
                            System.out.println("Rows " + selectedRowFrom
                                               + " to " + selectedRowTo + " are now selected.");
                    }
                }
            });
        ListSelectionModel colSM = theTable.getColumnModel().getSelectionModel();
        colSM.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    //Ignore extra messages.
                    if (e.getValueIsAdjusting()) return;

                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        System.out.println("No columns are selected.");
                    } else {
                        int selectedColFrom = lsm.getMinSelectionIndex();
                        int selectedColTo = lsm.getMaxSelectionIndex();
                        if (selectedColFrom==selectedColTo)
                            System.out.println("Column " + selectedColFrom
                                               + " is now selected.");
                        else
                            System.out.println("Columns " + selectedColFrom
                                               + " to " + selectedColTo + " are now selected.");
                    }
                }
        });
    }
0
 
LVL 8

Author Comment

by:razo
ID: 10937046
it is givin a syntax error on ListSelectionListener
do i have to import anything other what i imported at the beginning?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10937066
Sorry. Add:

     import javax.swing.event.*;
0
 
LVL 8

Author Comment

by:razo
ID: 10937136
ok one last thing there is a bug when i edit a cell i am not being able to select another cell
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10937182
So, you mean:
When editing one cell, you're not able to select another cell.
What happens? Do you get an error?
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 10937212
At least that's no problem with the demo app I gave you.

Change in MyOwnTableModel:
 
         public boolean isCellEditable(int row, int col) { return false; }
into
         public boolean isCellEditable(int row, int col) { return true; }

and add a function:

        public void setValueAt(Object value, int row, int col) {
            data[row][col] = value;
        }

Then you will be able to edit cells
0
 
LVL 8

Author Comment

by:razo
ID: 10937274
ok thanks look ill give u 100 more points if u could get me a way that when selecting 2 rows of the same column the lines between the two rows is removed
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10937526
First of all, thanks for accepting. That keeps us answering your future questions too.

About your extra Q:
Do you mean this:
you select row 4 and row 7 (of say column 3),
then - I suppose - you press a button <delete>
then you want row 5 and 6 to be removed?
Is it something like that?
0
 
LVL 8

Author Comment

by:razo
ID: 10937550
hi
just wanted if u can do it or not???
i appreciate ur answer either way
thanks
0
 
LVL 8

Author Comment

by:razo
ID: 10937577
no what i mean if the user selects rows 3 to 7 of a certain colum and he adds an appointment
then he sees the three columns having the same background color but with out having the dividing lines between them, the small line that distinguish a row from another row in the same column
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10937708
Mmmm.
I know the JTable functions:

 void setShowGrid(boolean showGrid)
          Sets whether the table draws grid lines around cells.
 void setShowHorizontalLines(boolean showHorizontalLines)
          Sets whether the table draws horizontal lines between cells.
 void setShowVerticalLines(boolean showVerticalLines)
          Sets whether the table draws vertical lines between cells.

but that's for the whole table, not for individual cells.
In coding everything is possible ;°)
So, there must be some way...
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10937805
... but I can't find one. :(
Sorry.
0
 
LVL 8

Author Comment

by:razo
ID: 10946797
thanks for trying
look can u try to put in an editable cell a textbox that holds the data and whose height could be changed???
something like outlook calander
i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10946892
Don't know if I understand...

>> a textbox that holds the data and whose height could be changed
Of no use. The cell height won't change because of containing a higher object.

If you want to change the height of a table row you can use JTable's setRowHeight() function:

public void setRowHeight(int row, int rowHeight)

Sets the height for row to rowHeight, revalidates, and repaints. The height of the cells in this row will be equal to the row height minus the row margin.

Parameters:
row - the row whose height is being changed
rowHeight - new row height, in pixels
Throws:
IllegalArgumentException - if rowHeight is less than 1

>>something like outlook calander
I don't see variable row heights in Outlook's calendar
???

>> i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
That's OK. (I guess you mean you'll post another Q than?)
But first I have to know what exactly you want.
0
 
LVL 8

Author Comment

by:razo
ID: 10946927
ok if u see outlook calandar when u add an appointment it shown as a text box in the the cell. this textbox can then be modified by increasing its length so that it extends over multiple cells....if we can do this than i don't need to change the cells at all

as for the points do i have to post another question? can i give you the extra points from here?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10947062
I see what you mean.
But that's not so easy.
First, you have to change the cursor when on a limit of an appointment (<> every horizontal line)
Secondly you have to change the background of the cells you move to while dragging.

I saw it quite easier:
1) Defining an appointment:
   - Select a range of cells
   - right-click and choose new appointment
   - new appointment dialog comes up (with the from/to times according to the selected cells; can be changed of course)
   - When closed possibly update the cells according to the changed time window

2) Changing the time window of an existing appointment (only not graphically)
   - right-click the appointment and choose edit (or somehting)
   - appointment dialog comes up again
   - When closed possibly update the cells according to the changed time window

I admit: being able to change the time window graphically is cool, but is it really a must for you?

>>can i give you the extra points from here?
No you can't. Once a Q is closed the points can't be incremented. (btw. more than 500 points is also impossible)
So posting another Q is the only option.
0
 
LVL 8

Author Comment

by:razo
ID: 10947350
ok i need it graphically it is important
i am ready to give u another 500 points if u can do it
but i have an idea if we add a textbox to the cell and then the user extends this textbox...not the cell, is that possible?
ok if u could do anything graphically can u let me know so that i post the new question
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10947621
>> if we add a textbox to the cell and then the user extends this textbox...not the cell, is that possible?
I'm afraid not. :(
You can define some text box as cell editor. But what then?
You can't update your table until you're done editing.
And in this case we want the table (cells) to follow the "editing". So... impossible I think.

If we want to do something like this, I think we will need to use a MouseListener and a MouseMotionListener on the table.
And then reacting (= adapting the selections of table cells) on mouse(drag)movements.
I'll see if I can (and find the time to) adapt the demo app with something like that.

I think it won't hurt to post a new Q.
Two or more experts always know more than one ;°)
(And if your Q isn't answered in your opinion, you can always make a request to delete it and refund the points)
0
 
LVL 8

Author Comment

by:razo
ID: 10947864
ok ill post a new question
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 96
custom annotations 9 39
check java version using powershell 13 93
Error in @AspectJ Based AOP with Spring 2 13
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question