Results 1 to 9 of 9
  1. #1
    mkjp2011 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Exclamation JPanel Contents not updating after adding Components

    Hello,
    I am trying to work with Swing. My problem is that I have create JSplitPane. On the Right is a JTree that I have created and that is working fine. On the right I have another inner JSplitPane. On the top of the JSplitPane I have JTextFields, on the bottom I add new JPanels dynamically during runtime. When I click on a item within the JTree it sends off an action that calls to a data base and populates the stuff on the right side of the application (JTextfields and the new dynamically created JPanels). The JTextfields are able to refresh correctly. However the bottom half of the JSplitPane will not refresh what so ever. Why could this be?

    Here are some snippets from my code:

    Setting up Inner JSplitPane and populating it:
    Java Code:
    private void setupForm(Timesheet timesheet, boolean useTimesheet) {
    		infoPane = new JPanel();
    		setupInfoPane(timesheet, useTimesheet);
    		infoPane.setVisible(true);
    		infoPane.setPreferredSize(new Dimension(200, 200));
                    //I am more concerned with this next part
                    //the setup of the taskPane. 
    		taskPane = new JPanel();
    		taskPane.setLayout(new BoxLayout(taskPane, BoxLayout.Y_AXIS));
    		setupTaskPane(timesheet, useTimesheet);
    		taskPane.setVisible(true);
    		taskPane.setPreferredSize(new Dimension(200, 200));
    		innerSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, infoPane,
    				taskPane);
    		innerSplit.setPreferredSize(new Dimension(500, 400));
    		innerSplit.setVisible(true);
    		SwingUtilities.updateComponentTreeUI(innerSplit);
    		this.form = new JScrollPane(innerSplit);
    		SwingUtilities.updateComponentTreeUI(form);
    		this.form.setVisible(true);
    		taskPane.validate();
    		infoPane.validate();
    		form.validate();
    		// SwingUtilities.updateComponentTreeUI(this.workspace);
                    //Workspace is the JFrame
    		workspace.setVisible(true);
    	}
    setupTaskPane
    Java Code:
    private void setupTaskPane(Timesheet timesheet, boolean useTimesheet) {
    		if (useTimesheet) {
    			TasksPanel pane = new TasksPanel();
    			tasksScroll = new JScrollPane();
    
    			for (int i = 0; i <= timesheet.getAssociatedTasks().size() - 1; i++) {
    				tasksScroll.add(pane.createPanel(timesheet.getAssociatedTasks()
    						.get(i)));
    				tasksScroll.setVisible(true);
    				tasksScroll.validate();
    			}
    			taskPane.add(tasksScroll);
    			taskPane.validate();
    		}
    
    	}
    taskPanel class. This class is used to create the new Panels to put into the TasksPane panel.
    Java Code:
    public JPanel createPanel(Task task) {
    		taskPane = new JPanel();
    		TitledBorder title;
    		title = BorderFactory.createTitledBorder(blackline, task.getTaskName()
    				.substring(0, 10));
    		taskPane.setBorder(title);
    		layout = new GroupLayout(taskPane);
    		taskPane.setLayout(layout);
    		setupPane();
    		projDescTF.setWrapStyleWord(true);
    		projDescTF.setText(task.getTaskDescription());
    		for (int i = 0; i <= task.getDays().size() - 1; i++) {
    			monTF.setText(task.getDays().get(i).getDayTotal() + "");
    			i++;
    			tuesTF.setText(task.getDays().get(i).getDayTotal() + "");
    			i++;
    			wedsTF.setText(task.getDays().get(i).getDayTotal() + "");
    			i++;
    			thursTF.setText(task.getDays().get(i).getDayTotal() + "");
    			i++;
    			friTF.setText(task.getDays().get(i).getDayTotal() + "");
    			i++;
    			satTF.setText(task.getDays().get(i).getDayTotal() + "");
    			i++;
    			sunTF.setText(task.getDays().get(i).getDayTotal() + "");
    		}
    		layout.setAutoCreateContainerGaps(true);
    		layout.setAutoCreateGaps(true);
    		return taskPane;
    	}

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

    Default

    If you are adding components dynamically, you must revalidate (so call revalidate). While I don't know exactly what you are populating with, a CardLayout or alternative method to update a single JPanel (rather than replace what is there) might be another approach.

  3. #3
    mkjp2011 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    I called the revalidate function and yet it still does not work.

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Here are some snippets from my code:
    See: Short, Self Contained, Correct Example for tips on how to post code.

  5. #5
    mkjp2011 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    Does anyone have any suggestions about my code? This seems to be the only problem, after this problem is solved everything is completed.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    Does anyone have any suggestions about my code?
    Have you shown us enough that we can compile and test it to see what happens?
    There could be code that you didn't post that effects what is happening.
    Try making a SSCCE that we can test with. See post#4

  7. #7
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by mkjp2011 View Post
    Does anyone have any suggestions about my code? This seems to be the only problem, after this problem is solved everything is completed.
    I notice that in setupTaskPane, you create a TasksPanel, add a scroll pane to it, and validate it, but you never add it to your GUI, so it doesn't surprise me that it never gets displayed...

  8. #8
    mkjp2011 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    But it does get added to it. I add it when I create the SplitPane, which then the SplitPane is added to the JFrame

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

    Default

    Without an SSCCE as has been suggested, we're staring at code and can point out things which may or may not be directly related to the problem - an SSCCE helps you as much as us. That being said, I recommend reading up on the following method in the API for a JScrollPane
    JScrollPane (Java Platform SE 6)
    In particular, the sentence "Applications should not add children directly to the scrollpane. "

Similar Threads

  1. updating a gameBoard (JPanel filled with JLabels)
    By Bloitz in forum AWT / Swing
    Replies: 3
    Last Post: 07-07-2011, 06:31 PM
  2. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 06:52 PM
  3. how to refresh the contents of a JPanel
    By pratim in forum AWT / Swing
    Replies: 1
    Last Post: 03-13-2011, 06:28 PM
  4. Setting/Updating a tabbed JPanel's name
    By dave_gardner in forum AWT / Swing
    Replies: 3
    Last Post: 03-03-2010, 12:49 PM
  5. Adding contents inside the JTabbedPane
    By javanewbie in forum New To Java
    Replies: 1
    Last Post: 05-27-2009, 12:02 PM

Tags for this Thread

Posting Permissions

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