pete stein

+ Follow
since Feb 23, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by pete stein

rahul taiwala wrote:use paint method instead of paintComponent and its working fine.....

This solution sounds very wrong. Sorry but it sounds like you're fixing the wrong thing, but I can't say what since I can't get your code to compile or run due to missing classes. One problem I see that is not causing your main question but can bite you later is that you have program logic within your paint/paintComponent method as indicated by my comment // **** here ****:

and program logic should not be in this method as you do not have full control as to when or if it will be called. Also it is strange to see a repaint() call within a paint/paintComponent method. If the JVM weren't smart, this would cause an infinite recursive cycle.
7 years ago
You should use a modifiable combo box model such as a DefaultComboBoxModel. Then you can add or remove elements from the model and the changes will be reflected in the JComboBox that uses this model.
7 years ago

Ben Jass wrote: I understand, but it's over. No need to extend it.

The current issue is over for you as you've answered your question, and I am truly glad for you, but this issue is also one commonly encountered by others here in the forum, and so I felt my points important enough to make if only for them.

Best of luck.
7 years ago

Ben Jass wrote: Again, I posted all the code above that someone would need to solve the problem, I don't see why I would need to go much further, call me lazy, but there's not point..doesn't matter now though, I solved it. I'm not trying to be rude, and I apologize if you have taken me the wrong way.

Let's not argue here since that's obviously not achieving anything, and you certainly aren't required to create an SSCCE, and no one is able to force you to do this, but as yet, no one has posted a solution to your question in the forum (even if you have solved it yourself), and maybe this is due to our not having enough information to allow us to create a solution in a reasonable period of time to expect a volunteer to commit. Please understand that to solve complex problems, we often have to create the SSCCE ourselves, and your creating it for us makes it much easier for us to understand your problem, test it, modify it, and correct it. The bottom line as I see it is if you want a correct solution quickly, then it's undoubtedly in your best interest to create and post an SSCCE. I think I speak for all in saying that if you put in the effort to create this, we would all appreciate it, and we would likely show our appreciation in trying to help you as much as possible.

7 years ago

Atakpa Daniel wrote:at the situation where i can avoid the use of Jbotton or check box but instead use JText field. Now the Jtex field will be sensitive to mouse point. Once it is clicked something should happen.

I think of a JTextField as a component that allows the user to enter or change text, and this is not what I believe you want. If I understand you correctly, you want to display rows of text that the user won't change but will select on mouse click. If correct, possible solutions include use of a JList that you've added an ItemSelectionListener to, or if you want to fully roll your own, then a grid of JLabels held in a JPanel where the JLabels have a MouseListener added to them.

7 years ago
OP, your code was very hard to read due to lack of formatting and misuse of code tags. Please review your post before finalizing it, and only paste already-formatted code. I have tried to fix your formatting and code tags. I will also move this thread to the Swing forum.

With regards to your question, your main issue is that you're calling Thread.sleep(...) on the EDT, the Swing event thread, and all this will do will be to put your application to sleep. Instead I recommend that you use a Swing Timer (javax.swing.Timer) to do your animation loop. The Swing tutorials will show you how to use this.
7 years ago
If you add a ChangeListener to the JTabbedPane's SingleSelectionModel (obtained via getModel()), you can listen for selection changes. I think that to listen for addition and removal of tabs / components, you'll want to add a ComponentListener to the JTabbedPane, though I'm not 100% sure if this is the only or best way to do this.
7 years ago

Paul Clapham wrote:Chocolate beer? I didn't believe it existed, but here's a link to what I found at my local supplier: Young's Double Chocolate Stout.

We have a local pub that carries the stuff, and it's as good as it sounds. Yum! :beerchug:
7 years ago

Henry Wong wrote:[2. Turbo Pascal. Although Pascal is not my favorite language, this is definitely my first "IDE" -- that proved that a good developer product can greatly enhanced productivity.

I strongly second this. Pascal was my very first language, and to be able to have my very own compiler and IDE and not have to share time on a Dec 10 was nonthing short of amazing.
My other two early experiences that shaped me was joining a TUG or "Turbo Users Group" in the Indianapolis area, where hobbiests like me could meet with real programmers. One in particular, a fellow named Alan Plantz was as kind and gentle a soul as ever there was, a phenomenal teacher, who taught me much and who met an early death. I am always thankful for having met him and still miss him even though it's been some 20 odd years since his passing.
7 years ago

Dss Ss wrote:
Which variable do you mean...?

You're trying to get the JTabbedPane. How many JTabbedPane variables does your program have? On a side note, why are any of the variables static?

Also, I'm not intentionally using vectors, where does that come?

I think that Containers hold their Components in an internal Vector. The JFrame holds only one Component, the contentPane, so in the components array it is held in position [0]. You're trying to get componets[1] which simply doesn't exist. But even if it did, this is not a good way to get your data. Rather your data should be accessible via a class getter method.
7 years ago

Campbell Ritchie wrote:Why are you using Vector, rather than one of the more modern implementations of List? Is it that it is required by one of the Components? I know there are things like Combo-boxes which still require Vector.
You are trying to gain access to the second (=index 1) member of a 1-member array or list.
Or: to put it another way: You have one element in the Vector and you are trying to access its second element.
Remember the first member of a List or array is no 0.

I think that he's not explicitly using Vector but rather is trying to get a reference to a component from a Container which likely uses a Vector to hold all of its components.
7 years ago
In your code:

You're getting components by using getComponents() and then using an array index to get the components. This is a very fragile way of getting a reference to an object. Why not use the variable that you already have in your class? As it is, it is likely that components[1] doesn't exist ([0] is probably the contentPane).
7 years ago
Hello and welcome to the Ranch!

So, what error message are you seeing, and what line of code causes the error? The more information you can give us, the better we'll be able to help you.

Much luck and again, welcome!
7 years ago

Lucas Smith wrote:Hi,
I am actually creating GUI in NetBeans visual editor. When I look at it in the design view - everything is OK. But when I compile that, some labels and other elements are not on their positions. Is there a recipe for this?

Hm, create the GUI by hand? I have to agree with Darryl that it's harder to create a decent flexible GUI with NetBeans code generator vs doing it by hand.
7 years ago

Mansoor Akhtar wrote:Thanks a lot Darryl. I am no more blaming the JVM for my "own lack of understanding" ... ;)
Pete, thanks for the reply.
The problem is solved by using the SwingWorker.

Glad you've got things working out! Please let us know how the whole project turns out.
7 years ago