Results 1 to 8 of 8
Thread: Problem with refreshing
- 01-11-2011, 04:01 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
Problem with refreshing
Hello
I have a textarea:
And when some button is clicked I want to create second textarea:Java Code:textarea = new JTextArea(); textarea.setFont(new Font("Courier", Font.PLAIN, 22)); scrollPane = new JScrollPane(textarea); scrollPane.setPreferredSize(new Dimension(300,300)); add(scrollPane, BorderLayout.CENTER);
Everything works fine but when I click the button, window is one can say "frozen", if you press any menu and close is, grey color still stays on textarea place, but when i resize window it goes back to what it was suppoused to be and I have 2 textareas. How to fix it?Java Code:remove(scrollPane); JTextArea textarea1 = new JTextArea(); textarea1.setPreferredSize(new Dimension(100,100)); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, textarea1); splitPane.setOneTouchExpandable(true); add(splitPane);
Thanks for responds.
Regards
- 01-11-2011, 05:32 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
When dynamically adding components to a container (after it has been validated), call revalidate() on the component.
- 01-11-2011, 07:43 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
Eh, I feel so dumb in java.
I tried to do splitPane.revalidate(); but it didn't gave effect I expected.
This is my whole code Ideone.com | Online Java Compiler & Debugging Tool
Could you tell me where to put revalidate?
I've just started programming in java, I'm though good at C and crossing over to new language is quite hard for me.
ThanksLast edited by misiom1; 01-11-2011 at 07:58 PM.
-
If removing a component, don't forget to also call repaint() on the container.
- 01-11-2011, 08:02 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
I did remove then repaint, then when I added a new component I put revalidate on new added component and I get a grey background, tried after adding a component ravalidate and repaint - effect is the same
- 01-11-2011, 11:02 PM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Post an SSCCE that demonstrates the problem (and recommended to place the code in the post itself - flanking the code with the [code][/code] tags)
- 01-12-2011, 10:23 AM #7
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
Here is program - http://www.misiom1.pl/test.jar Just pick menu "Kod" and press "kompiluj"
And here's code responsible for this change:
Java Code:Action compileAction = new AbstractAction("Kompiluj") { @Override public void actionPerformed(ActionEvent arg0) { remove(scrollPane); repaint(); JTextArea textarea1 = new JTextArea(); //add(textarea1, BorderLayout.SOUTH); //scrollPane.setPreferredSize(new Dimension(300,300)); textarea1.setPreferredSize(new Dimension(100,100)); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, textarea1); splitPane.setOneTouchExpandable(true); add(splitPane); splitPane.revalidate(); } };
- 01-15-2011, 12:37 PM #8
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Animations not refreshing
By zshaw in forum New To JavaReplies: 1Last Post: 12-26-2010, 12:05 AM -
JPanel not refreshing
By pahiker in forum SWT / JFaceReplies: 23Last Post: 07-14-2010, 02:59 PM -
Refreshing Jtable once again...
By Norther in forum AWT / SwingReplies: 2Last Post: 06-29-2010, 07:46 PM -
JTableHeader not refreshing
By aznboarder in forum AWT / SwingReplies: 4Last Post: 04-11-2009, 04:31 AM -
Bug in refreshing jsp
By anki1234 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 12-31-2007, 07:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks