Darryl Burke

+ Follow
since May 03, 2008
Darryl likes ...
Java Netbeans IDE Opera
Retired Electrical Engineer
Madgaon, Goa, India
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 Darryl Burke

Regexes are fun!

(So are Streams...)
10 months ago
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?
10 months 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.

10 months 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("  ", " ").
10 months 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:

11 months 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.
11 months ago
With Java8, why not replace the for-each loop with a Stream?  I guess this would do it:
11 months 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.
11 months ago
What output do you get for this code?
11 months 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.
11 months 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.
11 months ago
Use a java.util.Timer or a javax.swing.Timer, depending on your application.
1 year 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!
1 year ago