Swing GUI doesn’t wait for user input

You’re getting your msg String before the user has had a chance to change it, and the reason is that you’re thinking in a procedural kind of way, and this won’t work for Swing. In fact you’ve got to change your whole way of thinking in order to code event-driven programming like Swing. So msg … Read more

Leveraging the observer pattern in JavaFX GUI design

As noted here, the JavaFX architecture tends to favor binding GUI elements via classes that implement the Observable interface. Toward this end, Irina Fedortsova has adapted the original Converter to JavaFX in Chapter 5 of JavaFX for Swing Developers: Implementing a Swing Application in JavaFX. I’ve recapitulated the program below, updating to Java 8 and … Read more

JTable row limitation

I have to limit the number of rows in a JTable. If i have 100 records i need to display 10 on the initial loading of JTable. Use preferred size (+ an appropriate layout and layout constraint) to fix the size. I wish to put a button like “next”, and after each click it showing … Read more

Swing JToolbarButton pressing

As mentioned in Costis’ reply, you are probably after a JToggleButton. It might also be necessary to suppress the painting of the border, as in the 2nd tool bar in this example. import java.awt.*; import java.awt.image.*; import javax.swing.*; class ToggleBar { public static JToggleButton getButton( Image selected, Image unselected, boolean decorated) { JToggleButton b = … Read more

tech