Results 1 to 9 of 9
- 07-07-2011, 05:55 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 7
- Rep Power
- 0
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:
setupTaskPaneJava 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); }
taskPanel class. This class is used to create the new Panels to put into the TasksPane panel.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(); } }
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; }
- 07-07-2011, 06:11 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
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.
- 07-07-2011, 06:27 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 7
- Rep Power
- 0
I called the revalidate function and yet it still does not work.
- 07-07-2011, 10:31 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
See: Short, Self Contained, Correct Example for tips on how to post code.Here are some snippets from my code:
- 07-08-2011, 03:55 PM #5
Member
- Join Date
- Jul 2011
- Posts
- 7
- Rep Power
- 0
Does anyone have any suggestions about my code? This seems to be the only problem, after this problem is solved everything is completed.
- 07-08-2011, 04:13 PM #6
Have you shown us enough that we can compile and test it to see what happens?Does anyone have any suggestions about my code?
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
- 07-08-2011, 06:24 PM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
- 07-15-2011, 06:55 PM #8
Member
- Join Date
- Jul 2011
- Posts
- 7
- Rep Power
- 0
But it does get added to it. I add it when I create the SplitPane, which then the SplitPane is added to the JFrame
- 07-15-2011, 08:05 PM #9
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
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
-
updating a gameBoard (JPanel filled with JLabels)
By Bloitz in forum AWT / SwingReplies: 3Last Post: 07-07-2011, 06:31 PM -
Adding a jpanel to a customized Jpanel Class
By trishtren in forum AWT / SwingReplies: 7Last Post: 04-05-2011, 06:52 PM -
how to refresh the contents of a JPanel
By pratim in forum AWT / SwingReplies: 1Last Post: 03-13-2011, 06:28 PM -
Setting/Updating a tabbed JPanel's name
By dave_gardner in forum AWT / SwingReplies: 3Last Post: 03-03-2010, 12:49 PM -
Adding contents inside the JTabbedPane
By javanewbie in forum New To JavaReplies: 1Last Post: 05-27-2009, 12:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks