aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JPanel and text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel and text" Watch "JPanel and text" New topic
Author

JPanel and text

Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
I have a MyClass that extends Jpanel and it only contains one private instance variable(text) of String type.

there is a constructor :

public MyClass()
{
text = "";
}

and a paintComponent method

// paintComponent to be done in (a)
public void paintComponent(Graphics g)
{
super.paintComponent(g);

g.drawString(text, 10, 10);

}

that draws the string in th JPanel.

I want to create a void setText(String s) method that will accept a string and then it will update the text instance variable but it will also draw the text in the JPanel.

Any ideas?

Thank you very much!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6



GenRocket - A Test Data Generation Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel and text
 
Similar Threads
a question about JPanel
repaint() becomes slower as program runs
Is this a Java Program?
JPanel + text
Taking values from a text file inside paintcomponent