Results 1 to 3 of 3
  1. #1
    smallmos1 is offline Member
    Join Date
    Sep 2010
    Posts
    23
    Rep Power
    0

    Default unknown error - really need help

    i'm working on a gui that's part of a system for a project. have been compiling again and again to see how things are taking shape....added some code, took it away using ctrl+z a few times, now when i try to compile it i'm getting the following error below. i don't think i've undone anything but i can't figure out what's up. would really appreciate some help. error and code below:

    Java Code:
    Exception in thread "main" java.lang.IllegalArgumentException: horizontalAlignment
    	at javax.swing.JLabel.checkHorizontalKey(Unknown Source)
    	at javax.swing.JLabel.setHorizontalAlignment(Unknown Source)
    	at javax.swing.JLabel.<init>(Unknown Source)
    	at javax.swing.JLabel.<init>(Unknown Source)
    	at employeeSide.EnterDates.<init>(EnterDates.java:103)
    	at employeeSide.EnterDates.main(EnterDates.java:164)
    Java Code:
    package employeeSide;
    
    import java.awt.*;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import javax.swing.GroupLayout.Alignment;
    
    public class EnterDates extends JFrame //implements ActionListener
    {
    	//declare and initialise variables for the width and height of the window and buttons
    	private static final int FRAME_WIDTH = 600;
    	private static final int FRAME_HEIGHT = 400;
    	private static final int BUTTON_WIDTH = 100;
    	private static final int BUTTON_HEIGHT = 40;
    	
    	//declare submit and cancel buttons
    	private JButton submitButton;
    	private JButton cancelButton;
    	
    	//declare title, end date and start date labels
    	private JLabel startDateLabel;
    	private JLabel endDateLabel;
    	private JLabel title;
    	
    	private JComboBox dayBoxStart;
    	private JComboBox monthBoxStart;
    	private JComboBox yearBoxStart;
    	private JComboBox dayBoxEnd;
    	private JComboBox monthBoxEnd;
    	private JComboBox yearBoxEnd;
    	
    	private String[] dayListStart = {"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"};
    	
    	private String[] dayListEnd = {"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"};
    	
    	private String[] monthListStart = {"JAN","FEB","MAR","APR","MAY","JUN",
    						  		  	   "JUL","AUG","SEP","OCT","NOV","DEC"};
    	
    	private String[] monthListEnd = {"JAN","FEB","MAR","APR","MAY","JUN",
    	  		  						 "JUL","AUG","SEP","OCT","NOV","DEC"};
    	
    	private String[] yearListStart = {"2011","2012","2013","2014","2015","2016","2017","2018","2019","2020",
    						 		 	  "2021","2022","2023","2024","2025","2026","2027","2028","2029","2030",
    						 		 	  "2031","2032","2033","2034","2035","2036","2037","2038","2039","2040",
    						 		 	  "2041","2042","2043","2044","2045","2046","2047","2048","2049","2050",
    						 		 	  "2051","2052","2053","2054","2055","2056","2057","2058","2059","2060",
    						 		 	  "2061","2062","2063","2064","2065","2066","2067","2068","2069","2070",
    						 		 	  "2071","2072","2073","2074","2075","2076","2077","2078","2079","2080",
    						 		 	  "2081","2082","2083","2084","2085","2086","2087","2088","2089","2090",
    						 		 	  "2091","2092","2093","2094","2095","2096","2097","2098","2098","2099"};
    	
    	private String[] yearListEnd = {"2011","2012","2013","2014","2015","2016","2017","2018","2019","2020",
    									"2021","2022","2023","2024","2025","2026","2027","2028","2029","2030",
    									"2031","2032","2033","2034","2035","2036","2037","2038","2039","2040",
    									"2041","2042","2043","2044","2045","2046","2047","2048","2049","2050",
    									"2051","2052","2053","2054","2055","2056","2057","2058","2059","2060",
    								 	"2061","2062","2063","2064","2065","2066","2067","2068","2069","2070",
    								 	"2071","2072","2073","2074","2075","2076","2077","2078","2079","2080",
    								 	"2081","2082","2083","2084","2085","2086","2087","2088","2089","2090",
    								 	"2091","2092","2093","2094","2095","2096","2097","2098","2098","2099"};
    	
    	//declare three panels to attach components
    	private JPanel top;
    	private JPanel middle;
    	private JPanel bottom;
    	
    	public EnterDates()
    	{
    		//set size, title, what happens on exit and window resizing privileges
    		setSize(FRAME_WIDTH, FRAME_HEIGHT);
    		setTitle("Online Roster System");
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setResizable(false);
    		
    		//initialise content pane, set its colour and define layout 
    		Container cPane = this.getContentPane();
    		cPane.setBackground(Color.LIGHT_GRAY);
    		setLayout(new GridLayout(3,1));
    		
    		submitButton = new JButton("Submit");
    		submitButton.setSize(BUTTON_WIDTH,BUTTON_HEIGHT);
    		//submitButton.addActionListener(this);
    		
    		cancelButton = new JButton("Cancel");
    		cancelButton.setSize(BUTTON_WIDTH,BUTTON_HEIGHT);
    		//cancelButton.addActionListener(this);
    		
    		title = new JLabel("SELECT DATES TO VIEW BOOKED SHIFTS", SwingConstants.CENTER);
    		title.setFont(new Font("Arial", Font.BOLD, 24));
    		title.setSize(250, 50);
    		Box box = Box.createHorizontalBox();
    		box.add(Box.createHorizontalGlue());
    		box.add(title);
    		box.add(Box.createHorizontalGlue());
    		
    		startDateLabel = new JLabel("Select start date", SwingConstants.NORTH);
    		startDateLabel.setFont(new Font("Arial", Font.BOLD,16));
    		startDateLabel.setSize(40, 40);
    		
    		endDateLabel = new JLabel("Select finish date", SwingConstants.CENTER);
    		endDateLabel.setFont(new Font("Arial", Font.BOLD,16));
    		endDateLabel.setSize(40, 40);
    		
    		dayBoxStart = new JComboBox(dayListStart);
    		dayBoxStart.setSelectedIndex(0);
    		//dayBoxStart.addActionListener(this);
    		
    		dayBoxEnd = new JComboBox(dayListEnd);
    		dayBoxEnd.setSelectedIndex(0);
    		//dayBoxEnd.addActionListener(this);
    		
    		monthBoxStart = new JComboBox(monthListStart);
    		monthBoxStart.setSelectedIndex(0);
    		//monthBoxStart.addActionListener(this);
    		
    		monthBoxEnd = new JComboBox(monthListEnd);
    		monthBoxEnd.setSelectedIndex(0);
    		//monthBoxEnd.addActionListener(this);
    		
    		yearBoxStart = new JComboBox(yearListStart);
    		yearBoxStart.setSelectedIndex(0);
    		//yearBoxStart.addActionListener(this);
    		
    		yearBoxEnd = new JComboBox(yearListEnd);
    		yearBoxEnd.setSelectedIndex(0);
    		//yearBoxEnd.addActionListener(this);
    		
    		top = new JPanel();
    		top.setBorder(BorderFactory.createLineBorder(Color.black));
    		top.setBackground(Color.LIGHT_GRAY);
    		
    		middle = new JPanel(new FlowLayout());
    		middle.setBorder(BorderFactory.createLineBorder(Color.black));
    		middle.setBackground(Color.LIGHT_GRAY);
    		
    		bottom = new JPanel();
    		bottom.setBorder(BorderFactory.createLineBorder(Color.black));
    		
    		top.add(title);
    		
    		middle.add(startDateLabel);
    		middle.add(dayBoxStart);
    		middle.add(monthBoxStart);
    		middle.add(yearBoxStart);
    		middle.add(endDateLabel);
    		middle.add(dayBoxEnd);
    		middle.add(monthBoxEnd);
    		middle.add(yearBoxEnd);
    		
    		setLayout(new GridLayout(3,1));
    		cPane.add(title);
    		cPane.add(middle);
    		cPane.add(bottom);
    	}
    	public static void main(String[]args)
    	{
    		EnterDates dates = new EnterDates();
    		dates.setVisible(true);
    	}
    }
    thanks.

  2. #2
    smallmos1 is offline Member
    Join Date
    Sep 2010
    Posts
    23
    Rep Power
    0

    Default

    i just removed the SwingConstants on the first the JLabels... bit confusing but it's compiling again

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    SwingConstants is an Interface, I think it means that if you instantiate SwingConstants you have to call all of its methods/fields. I had a similar problem before when I tried to instantiate List e.g you can't do this:
    Java Code:
    import java.util.List;
    List list = new List();
    without shadowing all the methods in List

Similar Threads

  1. unknown html:form tag error.Pls help
    By yss1287b in forum New To Java
    Replies: 0
    Last Post: 12-14-2010, 11:31 PM
  2. Unknown NullPointerException Error...
    By ryanonnfire54 in forum New To Java
    Replies: 4
    Last Post: 11-16-2010, 07:23 PM
  3. Unknown error in Jtable...
    By blu_fox88 in forum AWT / Swing
    Replies: 2
    Last Post: 02-23-2010, 06:48 AM
  4. Unknown problem
    By sanchir0805 in forum New To Java
    Replies: 4
    Last Post: 03-20-2009, 04:56 AM
  5. Hi , Error in Jsp page is as "NumberFormatException.forInputString(Unknown Source)"
    By lavanya82 in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 02-20-2009, 08:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •