Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: User Interface Problems

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default User Interface Problems

    Hi,
    I am trying to create a specific user interface according to certain specifications given to me... I have figured out how to put the panels together and I have everything almost where I want it.

    I am having a lot of trouble figuring out how to make my schedule button a more reasonable size and also with bringing the JTextFields closer to their corresponding labels. If you compile this you will see how the two JTextFields are way too far away from their labels and the schedule button is way bigger than needed. Also the time JLabel is off to the left too far, I would like it more centered in the leftPanel. Any help would be much appreciated. thanks.

     
            private JTextField startAddress = new JTextField(10);
    	private JTextField endAddress = new JTextField(10);
    	private JList hourDisplay = new JList();
     
    	private JList minDisplay = new JList();	
    	private JScrollPane minPane = new JScrollPane(minDisplay);
     
     
    	private JTextArea itinDisplay = new JTextArea(22,50);
    	private JScrollPane itinPane = new JScrollPane(itinDisplay);
     
    	private JButton scheduleB = new JButton("Schedule");
     
     
    	JLabel itin = new JLabel("Itinerary");
    	JLabel start = new JLabel("Start:");
    	JLabel end = new JLabel("End:");
    	JLabel status = new JLabel("blah blah blah");
     
    	final static int maxGap = 20;
    	private double hour = 00;
    	private double min = 00;
    	JLabel time = new JLabel("time: " + hour + min);
     
    	public static final int WIDTH = 1000;
    	public static final int HEIGHT = 850;
    	public static final int hourLINES = 40;
    	public static final int charPerLine = 10;
    	public static final int minLINES = 40;
     
    	private JPanel mainPanel = new JPanel();
    	private JPanel leftPanel = new JPanel();
    	private JPanel rightPanel = new JPanel();
    	private JPanel southPanel = new JPanel();
    	private JPanel entryPanel = new JPanel();
    	private JPanel timePanel = new JPanel();
    	private JPanel buttonPanel = new JPanel();
    	private JPanel itinPanel = new JPanel();
    	private JPanel mapPanel = new JPanel();
     
     
     
     
     
    	public BusAppFrame() {
    		super("Bus Application");
    		setSize(WIDTH, HEIGHT);
    		setBackground(Color.DARK_GRAY);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		
    		entryPanel();
    		timePanel();
    		southPanel();
    		itinPanel();
    		mapPanel();
     
    		mainPanel.setLayout(new BorderLayout());
    		leftPanel.setLayout(new BorderLayout());
    		rightPanel.setLayout(new BorderLayout());
    		leftPanel.add(entryPanel, BorderLayout.NORTH);
    		leftPanel.add(timePanel, BorderLayout.CENTER);
    		leftPanel.add(southPanel, BorderLayout.SOUTH);
    		rightPanel.add(itinPanel, BorderLayout.NORTH);
     
    		mainPanel.add(leftPanel, BorderLayout.WEST);
    		mainPanel.add(rightPanel, BorderLayout.EAST);
     
    		status.setBorder(BorderFactory.createLineBorder(Color.black));
    		mainPanel.add(status, BorderLayout.SOUTH);
     
    		this.getContentPane().add(mainPanel);
     
     
     
     
     
     
     
    	}
    	private void entryPanel(){
    		entryPanel.setLayout(new GridLayout(3,1));
     
    		entryPanel.add(start);
    		entryPanel.add(startAddress);
    		entryPanel.add(end);
    		entryPanel.add(endAddress);		
    		entryPanel.add(timeOfDep);
     
    	}
    	private void timePanel(){
    		timePanel.setLayout(new GridLayout(1,2));
    		hourDisplay.setBorder(BorderFactory.createLineBorder(Color.black));
    		minDisplay.setBorder(BorderFactory.createLineBorder(Color.black));
    		hourDisplay.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    		minDisplay.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    		timePanel.add(hourDisplay);
    		timePanel.add(minDisplay);
     
    	}
     
     
    	private void southPanel(){
    		southPanel.setLayout(new BorderLayout());
    		//status.setBorder(BorderFactory.createLineBorder(Color.black));
    		southPanel.add(scheduleB, BorderLayout.CENTER);
    		//southPanel.add(status, BorderLayout.PAGE_END);
    	}
     
    	private void itinPanel(){
    		itinPanel.setLayout(new BorderLayout());
    		itinPanel.add(itin, BorderLayout.NORTH);
    		itinPanel.add(itinPane, BorderLayout.AFTER_LINE_ENDS);
    	}
            public static void main(String[] args) {
     
     
    		BusAppFrame obj = new BusAppFrame();
     
     
    		obj.setVisible(true);
     
    	}
    Last edited by pmg; April 1st, 2011 at 04:24 AM. Reason: added main method


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: User Interface Problems

    Why don't you use IDE instead of notepad?

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: User Interface Problems

    If you haven't yet, browse the following webpage: A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    Layouts can be mixed and matched, and calling setPreferredSize will help with the sizing

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: User Interface Problems

    Quote Originally Posted by Mr.777 View Post
    Why don't you use IDE instead of notepad?
    Where did the OP say s/he was using notepad? And besides, I actually recommend that newbies stick with a basic editor for as long as possible. Relying on an IDE, especially code generators, actually makes it harder to learn.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: User Interface Problems

    thanks for the replies, unfortunately I'm still not getting it.... When i use setPreferredSize it's not working properly the button's width refuses to change.

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: User Interface Problems

    Quote Originally Posted by KevinWorkman View Post
    Where did the OP say s/he was using notepad? And besides, I actually recommend that newbies stick with a basic editor for as long as possible. Relying on an IDE, especially code generators, actually makes it harder to learn.
    From his/her code, it seems like he uses notepad. Anyways, our concern is not what he/she uses, but what's his problem.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: User Interface Problems

    Quote Originally Posted by Mr.777 View Post
    From his/her code, it seems like he uses notepad.
    How so?

    Quote Originally Posted by Mr.777 View Post
    Anyways, our concern is not what he/she uses, but what's his problem.
    I can mostly agree with this, other than when people post IDE-generated code without understanding it. But you were the one that started the discussion on using an IDE instead of notepad. I just threw in my dissenting opinion in the conversation that you started.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. interface
    By nasi in forum Object Oriented Programming
    Replies: 5
    Last Post: September 2nd, 2010, 10:36 PM
  2. Comparable Interface
    By yelrubk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2010, 09:08 AM
  3. Interface problem please help!!
    By joff1403 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 6th, 2010, 11:09 AM
  4. SOMEONE PLEASE HELP ME ADD THE ACTIONLISTENER INTERFACE...
    By beginning2Understand in forum AWT / Java Swing
    Replies: 5
    Last Post: June 30th, 2009, 12:42 AM
  5. Problem while implementing a basic user interface menu
    By Rastabot in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 3rd, 2009, 04:38 PM