This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android 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
677
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?
1 year 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.

1 year 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("  ", " ").
1 year 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:

1 year 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.
1 year ago
With Java8, why not replace the for-each loop with a Stream?  I guess this would do it:
1 year 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.
1 year ago
What output do you get for this code?
1 year 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.
1 year 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.
1 year 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