This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!

Darryl Burke

Bartender
+ Follow
since May 03, 2008
Darryl likes ...
Java Netbeans IDE Opera
Retired Electrical Engineer
Madgaon, Goa, India
Cows and Likes
Cows
Total received
11
In last 30 days
0
Total given
15
Likes
Total received
678
Received in last 30 days
0
Total given
1196
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Darryl Burke

Thank you Stephan, I see where I went wrong.

Still assuming that only words with all-lowercase (i.e. [a-z]) are to be removed, how about this?
2 years ago

Stephan van Hulst wrote:

Darryl Burke wrote:What's wrong with sentence.replaceAll("(?:\\b)[a-z]*(?:\\b)", "")?  And if the double spaces left behind are an issue, that could be chained to .replace("  ", " ").


That regular expression does not take into account that the sentence could consist of characters other than a-z, A-Z and spaces.


Ah, I see.

Stephan van Hulst wrote:Also, the second replace would have to be performed multiple times until there are no more changes.


Um, no.

String#replace(CharSequence target, CharSequence replacement) wrote:Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

2 years ago
What's wrong with sentence.replaceAll("(?:\\b)[a-z]*(?:\\b)", "")?  And if the double spaces left behind are an issue, that could be chained to .replace("  ", " ").
2 years ago
Your problem lies in that the DocumentListener updates the slider value and the slider's ChangeListener tries to update the text field.  One way to get around this is to use a boolean flag.  Something likeThis limited example assumes both listeners are in the same class and will need to be enhanced to work between classes.  I would probably approach this with a class containing ONE text field and ONE slider, possibly encased in a JPanel, and two anonymous listeners; then add three instances of the class to the GUI.

Campbell Ritchie wrote:I am pretty sure that is what I did.


Sorry, I was confused by this version you posted later.

Campbell Ritchie wrote:

2 years ago

Campbell Ritchie wrote:Since paintShape takes a Graphics parameter, can you simply use a method reference?


Probably not.  I plead guilty to not reading the method declaration in earlier posts, but if that method requires a Graphics reference, how would you invoke it from a Timer's ActionListener?  Rather, the Timer would simply repaint() the panel and paintComponent(...) would take care of the rest.
2 years ago
With Java8, why not replace the for-each loop with a Stream?  I guess this would do it:
2 years ago
Hello Penney, and welcome to the Ranch!  You're probably adding the data to an instance of Gui_Main that is different from the one you have displayed.  I say 'probably' because the code snippets you have posted are really not enough to diagnose the problem.  To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example).

Also, to conform to Java conventions, that class could be named GuiMain, not Gui_Main (it would be better still if the class name implied its purpose).  Your package names Parts, Products and Inventory should be lowercase i.e. parts, products, inventory.

Since this is a Swing and not a JavaFX question, I've added it to the correct section of the Ranch.
2 years ago
What output do you get for this code?
2 years ago

Pierre-Yves Saumont wrote:I would be interested in knowing he exact version used.




Looks like a bug that was fixed in later updates.
2 years ago
I found that javac (jdk1.8.0) compiles it without reporting an error; NetBeans on the other hand flags the error mentioned by Pierre-Yves.
2 years ago
Use a java.util.Timer or a javax.swing.Timer, depending on your application.
2 years ago
Hi Carlos and welcome to the Ranch!  We have a page about How To Ask Questions On Java Ranch -- follow even half the advice enshrined there and you're gold!
2 years ago