Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Can I use repaint() on a JFrame?

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have got a main class which is JFrame and other sub class JPanel. Could u please tell me how to repaint() the entire JPanel once a component(JButton)present in the panel is pressed?
with warm regards,
Arun.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just call repaint() if you are inside the panel code, or call myPanel.repaint() from a main method or code outside the panel.
If you post the code that you are working with, we could show you better.
 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cindy,
Thanks for the suggestion. I tried out but it didn't serve my purpose. I will tell u what I want.
I have a class MainClass which has got 2 JTabbedPanes which are 2 JPanels ie P1,P2.
In P1,I get some user values thru some JTextFields and insert into the database. Then next Panel P2 is used for modifiying the P1's values.
In P2,the values are retreived from the database and put in a JComboBox which is used for further manipulation.
The problem is that whenever I insert values into P1,the new values don't get immediately updated in P2. I have to quit the application and run the application once again. This defeats the very purpose of my app. I want that P2 should reflect my new values immediately when they are inserted into database thru P1.
The outline pgm code
-------------------
public class MainClass extends JFrame implements ChangeListener
{
JTabbed tp;
MainClass()
{
// Declare 2 Tabbed Panes.
tp.add(p1,new p1());
tp.add(p2,new p2());
// add Listener
// add tabbedpane to the container.
}

// Listener method
{
if (selected index = 0)
new p1();
if (selected index = 1)
new p2();
}
public static void main()
{
}

} // end of MainClass
class p1 extends JPanel implements ActionListener
{
JTextField tf1;
JTextField tf2;

JButton submit;

p1()
{
// declare the textfields,button and add to the
content pane
// add Action Listener
}

actionperformed()
{
// get the text field value
// insert into the database
}
} // end of class p1
class p2 extends JPanel implements ActionListener
{
JComboBox jcbox tf;
JTextField tf1;
JButton submit;

p2()
{
// get the values from the database
// put into the combobox.
// the pblm ie the latest values are not being displayed
}

actionperformed()
{
// get the values from the combo box for processing
}
} // end of class p2
with warm regards,
Arun.

 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you doing this


p2()
{
// get the values from the database
// put into the combobox.
// the pblm ie the latest values are not being displayed
}


 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic