Results 1 to 8 of 8
  1. #1
    misiom1 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Problem with refreshing

    Hello
    I have a 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);
    And when some button is clicked I want to create second textarea:

    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);
    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?

    Thanks for responds.

    Regards

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    When dynamically adding components to a container (after it has been validated), call revalidate() on the component.

  3. #3
    misiom1 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    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.

    Thanks
    Last edited by misiom1; 01-11-2011 at 07:58 PM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    misiom1 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    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

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    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)

  7. #7
    misiom1 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    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();
    		}
    		
    		
    	};

  8. #8
    misiom1 is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Animations not refreshing
    By zshaw in forum New To Java
    Replies: 1
    Last Post: 12-26-2010, 12:05 AM
  2. JPanel not refreshing
    By pahiker in forum SWT / JFace
    Replies: 23
    Last Post: 07-14-2010, 02:59 PM
  3. Refreshing Jtable once again...
    By Norther in forum AWT / Swing
    Replies: 2
    Last Post: 06-29-2010, 07:46 PM
  4. JTableHeader not refreshing
    By aznboarder in forum AWT / Swing
    Replies: 4
    Last Post: 04-11-2009, 04:31 AM
  5. Bug in refreshing jsp
    By anki1234 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-31-2007, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •