• Post Reply Bookmark Topic Watch Topic
  • New Topic

refreshing JPanel after data being updated  RSS feed

 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

First time posting and first real issue I have had since started to learn JAVA. Still relative new to JAVA so any help would be useful

I am writing a program to record sight marks for archery.
I created a JPanel screen with the marks shown (pulled from a database). I then have an update button for each sight which opens a JOptionPane method
Clicking OK on this pane updates the database with the new values. If I close the program down and re-load it shows the new data correctly

My first real issue is that I not found a good way to refresh / reload the screen to show the updated values.

Here is some of the Code if that helps with that I am trying to do. Calling this method within a CardLayout from a different class


Within the actionPerformed area I am just calling the OptionBox method with values when the update button is pressed.

Within the OptionBox method I am displaying the sight mark values correctly and clicking OK on it fires an update to the database but I am stuck on refreshing / reloading the screen

thanks
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're looking for a way to refresh or reload the screen, then you're looking for the wrong thing. I see you have some components there, some JLabels and some JTextFields anyway. If you want to change any of them, then they do have methods which allow you to do that. For example if you wanted to change the data shown in a JTextField, you would simply call its setText() method with the new value.
 
randy orton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello james........
Just wrire a mouse listener for a button(refresh).Everytime you click on it just update everything using setText()
by passing new values to setText() everytime.Handle this using mouseclicked() method of mouselistener.
bye ,have a good time........
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
randy orton wrote:hello james........
Just wrire a mouse listener for a button(refresh).

Wrong advice. The listener to use with a JButton is an ActionListener, not MouseListener (unless you have very unusual design requirements).

Recommended reading: How to Use Buttons, Check Boxes, and Radio Buttons
 
randy orton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
randy orton wrote:hello james........
Just wrire a mouse listener for a button(refresh).

Wrong advice. The listener to use with a JButton is an ActionListener, not MouseListener (unless you have very unusual design requirements).

Recommended reading: How to Use Buttons, Check Boxes, and Radio Buttons

I know that but thanks for the recommendation.You can do that with a action listener too.
 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice

I added a settext() to update both the textfields after I have updated them to the database
These requests are updated in the optionbox method

This works and the fields are updated correctly but is creating something strange.

All the distancePanels that are created as you can see add two labels (NotchLabel and PositionLabel)
After I run the settext on the two fields the two labels on the last distancePanels disappear.

I can provide a screenshot if it helps
 
James Dudley
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added images to give you an idea of the issue
image_after.JPG
[Thumbnail for image_after.JPG]
image_before.JPG
[Thumbnail for image_before.JPG]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!