Simple collection of the months component (without corresponding calendar?)

I feel that it can be ridiculously easy to answer...

I am looking for a component of the months picking it is simply an extension of something that already exists.

My first instinct was to look at the JXMonthView that is included inside SwingX. Basically, my ideal component would be one that includes only the month part up to the selection page of the JXMonthView component with "traversable' set to true. In other words, a control that allows you to choose a month in the year using a schema of forward/reverse. Unfortunately, I can't find a good way to replace the functionality of the class such that only the top header is included.

I tried to get into the guts of the code, but it was like the best thing to do was to replace the layoutContainer inside BasicMonthViewUI function. Then I realized that this feature is part of a private class. I missed a great way to hide just that little of the Panel? I also considered replacing the functions of the painting, but my fear is that the component request too much space because it's just not 'paint' the month but still allocates space for this.

I think that, perhaps, a self-made simple control may be the best solution? I'm just trying to stay away from possible much custom work I hope to make the control as portable as possible between platforms.

Thank you!

aardvarkk wrote:
I'm looking for what you might call a "horizontal spinner" or scroll bar, in which you have a front and back button on each side of months he throws back a month and back. Also it should technically go back into previous years and to enter in the new.

Here is something of a JSlider in months and JButtons in the years. Because I'm not that familiar with Date/calendar, there is probably a better way to extract the necessary information (exercise for the OP), but this comes from the Swing stuff demos:

import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;

import javax.swing.*;
import javax.swing.event.*;

public class MonthScroller extends JPanel
{
  String[] months;
  JSlider slider;
  JButton btnPrevious, btnNext;
  JLabel displayMonth, displayYear;
  int month, year;

  public MonthScroller()
  {
    months = Arrays.copyOf(
        DateFormatSymbols.getInstance().getShortMonths(), 12);
    month = Calendar.getInstance().get(Calendar.MONTH);
    year = Calendar.getInstance().get(Calendar.YEAR);

    displayMonth = new JLabel(months[month]);
    displayYear = new JLabel(String.valueOf(year));

    slider = new JSlider(0, 11, month);
    slider.setMinorTickSpacing(1);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.addChangeListener(new ChangeListener(){
      public void stateChanged(ChangeEvent e)
      {
        month = slider.getValue();
        displayMonth.setText(months[month]);
      }
    });

    btnPrevious = new JButton("<");
    btnPrevious.addActionListener(new YearIncrementer(-1));
    btnNext = new JButton(">");
    btnNext.addActionListener(new YearIncrementer(1));

    add(btnPrevious);
    add(slider);
    add(btnNext);
    add(displayMonth);
    add(displayYear);
  }

  private static void createAndShowUI()
  {
    JFrame frame = new JFrame("Month Scroller");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new MonthScroller());
    frame.pack();
    frame.setLocationRelativeTo( null );
    frame.setVisible( true );
  }

  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        createAndShowUI();
      }
    });
  }

  class YearIncrementer implements ActionListener
  {
    int increment;
    YearIncrementer(int increment)
    {
      this.increment = increment;
    }

    public void actionPerformed(ActionEvent e)
    {
      year += increment;
      displayYear.setText(String.valueOf(year));
    }
  }
}

Tags: Java

Similar Questions

Maybe you are looking for

  • Microsoft OneNote 2003

    Just bought my first toshiba laptop... There is a sticker that onenote is installed on it.But despite all my efforts, it will not start. I need a key code but I have no one. Someone knows what to do and how to get onenote? Thank you!

  • Satellite L750D - update in Win 7 32 bit for win 10 64 bit

    The installation was successful? Well win 10 came and I changed a few things in the start when the laptop computer just restarted. Windows 10 tried to solve the problem and said that it was impossible.I tried various recovery options that are offered

  • I have some trouble transfer my image file on a DVD + R?

    I use one: computer Hp Pavilion DV5237CL. My operating system is: Windows XP Media Center Edition, SP3. I r: Matshita DVD - RAM UJ-years 840 catagoried under CD-ROM/DVD-ROM drives.  I have also studied this desire to discover that he is able to write

  • Officepro HP 8600: How to bypass the color cartridges empty on my HP Officepro 8600 to print only in black

    I am wanting to print Grayscale / black only, still does not allow me to print because I have empty color cartridges. How can I get around this? I tried changing the settings Thank you very much

  • E-mail Outbox freezes

    After opening an e-mail message and tab and then on the button 'send '. set the contents of the email go 'Send' but is there... In other words it does not 'Outbox' move in my "Sent items" folder However, the message transmits to recipients. What can