Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for creating a working Java GUI

Current License: CC BY-SA 3.0

49 events
when toggle format what by license comment
Jun 19, 2012 at 13:39 vote accept user1066524
Nov 26, 2011 at 17:14 history edited trashgod CC BY-SA 3.0
Reformatted, copyedited; please revert if incorrect.
Nov 26, 2011 at 17:08 comment added user1066524 lol... yeah i got kind of carried away with the comments. i pressed enter to go to the next line not realizing it had continuous text wrap and it then entered them each as comments. But wow, how these comments helped.
Nov 26, 2011 at 11:33 history edited kleopatra
edited tags
Nov 26, 2011 at 11:33 comment added kleopatra @user1066524 woooowww ... 30++ comments - can't resist adding yet another one :-) BTW, you can edit your question and add any code/stacktrace there, that's wayyy easier to read
Nov 26, 2011 at 6:13 comment added Eric Rosenberg The combobox thing is probably because you are adding all the combos to the center of the BorderLayout. See Will's answer below, he has a lot of good information and clearly spend a lot of time on it. If you find it helpful you should accept it.
Nov 26, 2011 at 6:13 comment added user1066524 thank you so much for your help Eric. I really appreciate it!
Nov 26, 2011 at 6:07 comment added user1066524 okay. the good news is that some components are appearing a viewer! thank goodness. but now like you said, the combobox has taken up the screen. it's looking like one of those customcomboboxes which i don't want. here's what it looks like right now: docs.oracle.com/javase/tutorial/figures/uiswing/components/…. i'm wanting four of these: docs.oracle.com/javase/tutorial/figures/uiswing/components/…. some how i have to change something about the way it is being laid out.
Nov 26, 2011 at 6:06 answer added Will Hartung timeline score: 4
Nov 26, 2011 at 5:57 comment added Eric Rosenberg I believe if you do that the textArea will replace the listPane. I'd suggest commenting out most of the code so you get something coming up on the screen, then slowly building up the GUI. Your GUI building code seems to have lots of little issues in it. Like for example, you have listPanel.setVisible(true) which you shouldn't need.
Nov 26, 2011 at 5:52 comment added user1066524 okay, i see what you mean. so could i just add(listPanel), BorderLayout.SOUTH); and then add(textArea),BorderLayout.SOUTH);
Nov 26, 2011 at 5:48 comment added user1066524 yeah listPane is : // list box continued JScrollPane listPane = new JScrollPane(); listPane.getViewport().add(list); listPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); and the scrollPane is : // sets up textarea textArea = new JTextArea(5,10); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); listPanel.add(listPane);
Nov 26, 2011 at 5:48 comment added Eric Rosenberg you might not have meant to do that (add a component to CalculateBillPanel using GBC) but that IS what your code is doing.
Nov 26, 2011 at 5:45 comment added user1066524 no, i wasn't doing that. but what i was trying to do was I created a panel called listPanel for the list box and i was trying to use a gridbag to put the listbox over a textarea.
Nov 26, 2011 at 5:43 comment added Eric Rosenberg not, what I meant... so my comment about. The problem is coming from line 204 of CalculateBill.
Nov 26, 2011 at 5:40 comment added user1066524 yeah, i already figured that the word 'fram' was supposed to be 'frame.' but unfortunately that wasn't the problem.
Nov 26, 2011 at 5:40 comment added Eric Rosenberg Looks like where you are laying out listPane you start trying to add components using GBC but you declared the panel to be a BorderLayout. Are you sure you didn't mean to have listPane.add()?
Nov 26, 2011 at 5:39 comment added user1066524 CalculateBill line 204 is: add(listPane, c);
Nov 26, 2011 at 5:36 comment added Eric Rosenberg What line of code is CalculateBill.java line 204?
Nov 26, 2011 at 5:34 comment added Eric Rosenberg Sorry, posted code without testing. I'll edit my answer.
Nov 26, 2011 at 5:28 comment added user1066524 but unfortunately..........Exception in thread "main" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null) at java.awt.BorderLayout.addLayoutComponent(BorderLayout.java:426) at java.awt.Container.addImpl(Container.java:1120) at java.awt.Container.add(Container.java:966) at assignment12.CalculateBill.<init>(CalculateBill.java:204) at assignment12.Main.main(Main.java:19)
Nov 26, 2011 at 5:28 comment added user1066524 and i changed the textfields. I can't believe i missed that!
Nov 26, 2011 at 5:27 comment added user1066524 okay. i changed the main method to what you advised. looks advisable.
Nov 26, 2011 at 5:19 answer added Andrew Thompson timeline score: 2
Nov 26, 2011 at 5:16 comment added Eric Rosenberg you need textTableNum = new JTextField(); before you try to use the variable.
Nov 26, 2011 at 5:15 answer added Eric Rosenberg timeline score: 2
Nov 26, 2011 at 5:15 comment added Andrew Thompson BTW - when I mentioned that using an applet would cause problems, frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - a sand-boxed applet is not permitted to do that. ;)
Nov 26, 2011 at 5:14 comment added user1066524 when i put init() in the main method and then that went to method createAndShowGUI() why didn't this initialize the constructor for CalculateBill? wouldn't that initialize the components? textTableNum is a JTextfield which is null upon starting the applet. so how would i avoid this?
Nov 26, 2011 at 5:11 comment added user1066524 line 35 MAIN is: CalculateBill newContentPane = new CalculateBill();
Nov 26, 2011 at 5:11 comment added Eric Rosenberg Yup, you aren't initializing the variable.
Nov 26, 2011 at 5:10 comment added Eric Rosenberg ok, that would mean textTableNum hasn't been initialized yet.
Nov 26, 2011 at 5:09 comment added Eric Rosenberg That is enough stack trace, but what code is on line number 186 of CalculateBill.java?? The problem appears to be on that line
Nov 26, 2011 at 5:08 comment added user1066524 line 186 is textTableNum.addActionListener(this);
Nov 26, 2011 at 5:08 comment added user1066524 that's all that showed up in the console. i apologize for not being able post the whole stack trace in my question.
Nov 26, 2011 at 5:07 comment added Eric Rosenberg Which line of code is: CalculateBill.java:186)
Nov 26, 2011 at 5:06 comment added user1066524 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Nov 26, 2011 at 5:06 comment added user1066524 at java.awt.EventQueue.access000ドル(EventQueue.java:101) at java.awt.EventQueue3ドル.run(EventQueue.java:666) at java.awt.EventQueue3ドル.run(EventQueue.java:664) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain1ドル.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:675) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
Nov 26, 2011 at 5:05 comment added user1066524 at assignment12.CalculateBill.<init>(CalculateBill.java:186) at assignment12.Main.createAndShowGUI(Main.java:35) at assignment12.Main.access0ドル(Main.java:31) at assignment12.Main1ドル.run(Main.java:21) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
Nov 26, 2011 at 5:05 comment added Andrew Thompson "I get this in the console: stackflow won't let me post it." Why not? If it is too long, trim all but the first few lines.
Nov 26, 2011 at 5:04 comment added Eric Rosenberg did the NullPointerException include a stack trace? If so please post
Nov 26, 2011 at 5:04 comment added user1066524 Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
Nov 26, 2011 at 5:03 comment added user1066524 the applet viewer appears. and that's all.
Nov 26, 2011 at 5:03 comment added Eric Rosenberg your error from the console isn't showing in your post
Nov 26, 2011 at 5:02 comment added Andrew Thompson "I decided to try and change the program to a JApplet to see if this would help" It introduces more challenges. Change it back.
Nov 26, 2011 at 5:02 history edited user1066524 CC BY-SA 3.0
added 14337 characters in body; edited tags
Nov 26, 2011 at 4:58 comment added Dave Newton Have you gotten a small, minimal GUI app running?
Nov 26, 2011 at 4:51 history edited user1066524 CC BY-SA 3.0
added 14337 characters in body; edited tags
Nov 26, 2011 at 4:50 history edited 一二三
edited tags
Nov 26, 2011 at 4:47 history asked user1066524 CC BY-SA 3.0
toggle format

AltStyle によって変換されたページ (->オリジナル) /