Hi guys,
Need help with my project it is an offline personal dairy so i have to display calendar i did but the problem is it doesn't look like a calender at all it's just look like an collection of buttons i tried to set border as setBorder(1,1,1,1) but that doesn't really helped no difference if i applied that. So i want some suggestions to improve it.

here is i attatched a screenshot

thanks in advance
regards Tizon

Well i don't think it looks so bad, but if you would like the buttons to be closer to each other, i.e. no gap between them you could try to set the vgap and hgap for the your layout. I suppose you are using gridlayout for the calendar, just class gridlayout.setHgap(0), and the same for setVgap.

I see now that the weekdays are all mixed up, you should try to make a timeline for weekdays on the top, monday to sunday and then for every month put the days in the right place. Should be to hard, just calc. what day the first of the month begins with and start with adding buttons in the grid from there, add empty buttons or buttons from the previous month before that. The width of your grid should apparently be the same as number of weekdays.

You maybe also want to make the date picker a bit more separated from the calendar. Right now it looks a little mixed up. There are also lots of free date pickers to download if you don't want to make it yourself, just google java date picker or something.

You could also maybe write your own component for the days instead of using a jbutton. That way you can make it look less like a button and also put more information in it. Maybe show the day of month in the top right or left corner and then bullet point information about its content.

One last thing is a forward and backward button which is probably more useful than a date picker of any kind, so you can quickly move between days/weeks/months.

You could also maybe write your own component for the days instead of using a jbutton. That way you can make it look less like a button

Hey thanks for the quick reply and
Nice suggestions

But it is clear that those buttons are separated using those lines i just want all as a single like in the picture i attached and i also reworked the alignment and the gap between buttons and posted a screenshot.

as u have mentioned to write your own component unlike using a JButton i couldn't get it could u elaborate it please.

and ammm trying to explain my thoughts as well as i can

first the buttons look flat and attached when mouse enters the number it bulges by using mouse entered. you see that is what i intended to do
for that i thought to make an icon and overlay it when mouse entered but cant get ideas of implementation though :?:
thanks again in advance

What i meant was, if you would like to not use a JButton as the representation for your days in the calendar, you could make a class that extends for instance a JPanel and then add whatever components and use whatever layouts that are necessary and customize the appearance to your liking.

What i always do is to draw an image of what I want a GUI component to look like, and then i implements it. You can also make your new class listen to mouse event just like a button to change its appearance and act on events accordingly.

But your calendar doesn't in my opinion look bad now. If you want a more paper calendar look to it, you could create class that extends JPanel, set its background to white or whatever, add a simple black border to it, and a centered label showing the day number. You can then make the constructors take in the same thing as a JButton does, i.e. a string, or whatever information you want to display in that component.

If you want to show an image in the button on mouse over event just add a MouseListener to the buttons and show your image when the mouse has entered and remove it when the exits.

http://java.sun.com/javase/6/docs/api/java/awt/event/MouseListener.html

What i meant was, if you would like to not use a JButton as the representation for your days in the calendar, you could make a class that extends for instance a JPanel and then add whatever components and use whatever layouts that are necessary and customize the appearance to your liking.

What i always do is to draw an image of what I want a GUI component to look like, and then i implements it. You can also make your new class listen to mouse event just like a button to change its appearance and act on events accordingly.

But your calendar doesn't in my opinion look bad now. If you want a more paper calendar look to it, you could create class that extends JPanel, set its background to white or whatever, add a simple black border to it, and a centered label showing the day number. You can then make the constructors take in the same thing as a JButton does, i.e. a string, or whatever information you want to display in that component.

If you want to show an image in the button on mouse over event just add a MouseListener to the buttons and show your image when the mouse has entered and remove it when the exits.

http://java.sun.com/javase/6/docs/api/java/awt/event/MouseListener.html

Thanks for the reply
that adding label's will solve it
But a label does not respond to the user input so what if the user clicked on a date i.e label :-/

You can add a MouseListener to a JLabel just as a JButton the difference is that a label will not change its appearance when you move you mouse over it or click, you'll have to do that yourself.

For example...

JLabel label1 = new JLabel("label");
label1.addMouseListener(this);

"this" must then implement the MouseListener interface in order to listen to the events.

You can also do the almost same thing this way.

label1.addMouseListener( new MouseAdapter() {
   public void mousePressed(MouseEvent e) {
      //code to handle mouse pressed.
   }
   public void mouseEntered(MouseEvent e) {
      //code to handle mouse entered,
   }
} );

Check out the java api for MouseListener and MouseAdapters, and google some tutorial if you feel uncertain about how to use it.

You can add a MouseListener to a JLabel just as a JButton the difference is that a label will not change its appearance when you move you mouse over it or click, you'll have to do that yourself.

For example...

JLabel label1 = new JLabel("label");
label1.addMouseListener(this);

"this" must then implement the MouseListener interface in order to listen to the events.

You can also do the almost same thing this way.

label1.addMouseListener( new MouseAdapter() {
   public void mousePressed(MouseEvent e) {
      //code to handle mouse pressed.
   }
   public void mouseEntered(MouseEvent e) {
      //code to handle mouse entered,
   }
} );

Check out the java api for MouseListener and MouseAdapters, and google some tutorial if you feel uncertain about how to use it.

k thanks for your help
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.