Results 1 to 8 of 8
  1. #1
    Ravanelly is offline Member
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Default JPanel inside Jtabbed isn't display

    Hello,

    I have
    I have the fowling code from below.
    Explication:I have a HashMap(alarmsTabbedPane) and here I add a key and a JPanel for every key. And here in every tab I add a Jpanel who is create with :alarmPanels.put(key, ShowAlarmsDialogHelper..constructAlarmPanel(alarmD ata, translator));
    ShowAlarmsDialogHelper..constructAlarmPanel is a class who create a Jpanel with some Jtext area.

    My problem is that sometime in a tab (example with key "1") it isn't display the Jpanel, I don't see nothing inside Jpanel like in picture that I attach.
    Do you now why?It have connection with SwingUtilities.invokeLater.

    Thank you in advanced

    Java Code:
    final Map alarmPanels = new HashMap(alarmKeys.size())
    
    for (int i = 0; i < alarmKeys.size(); i++) {
    				String key = (String) alarmKeys.get(i);
    				Map alarmData;
    				if ((alarmData = (Map) alarms.get(key)) != null) {
    					try {
    						alarmPanels.put(key, ShowAlarmsDialogHelper
    								.constructAlarmPanel(alarmData, translator));
    						addNotify();
    						// repaint();
    					} catch (Throwable e) {
    						e.printStackTrace();
    					}
    				}
    			}
    
    
    	SwingUtilities.invokeLater(new Runnable() {
    				public void run() {
    					
    					alarmsTabbedPane.removeAll();
    					for (int i = 0; i < alarmKeys.size(); i++) {
    						String key = (String) alarmKeys.get(i);
    						JPanel panel = (JPanel) alarmPanels.get(key);
    						if (panel == null) {
    							continue;
    						}
    						String title = (String) titles.get(key);
    						title = title == null ? "Unknown Counter" : title;
    						alarmsTabbedPane.add(title, panel);
    
    
    					pack();
    	
    				}
    
    			});
    
    			new Timer("Validator").schedule(new TimerTask() {
    
    				public void run() {
    					SwingUtilities.invokeLater(new Runnable() {
    						public void run() {
    							pack();
    
    						}
    					});
    					
    				}
    			}, 50);
    Attached Thumbnails Attached Thumbnails JPanel inside Jtabbed isn't display-empty-jpanel.jpg  
    Last edited by Ravanelly; 06-07-2010 at 01:13 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Where does your code build the panels?
    There isn't enough code shown to be able to help.

  3. #3
    Ravanelly is offline Member
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Default

    Hy,

    The code from class that I past code before :
    Java Code:
    final JPanel alarmspaPanel = new JPanel(new BorderLayout());
    		alarmspaPanel.setBorder(BorderFactory
    				.createTitledBorder("alarmspaPanel"));
    
    		alarmsTabbedPane = new JTabbedPane();
    		alarmspaPanel.add(alarmsTabbedPane, BorderLayout.CENTER);
    And here is the code for ShowAlarmsDialogHelper..constructAlarmPanel :

    Java Code:
    public class ShowAlarmsDialogHelper {
    
    	private static final Insets insets = new Insets(5, 5, 5, 5);
    
    	private ShowAlarmsDialogHelper() {
    	}
    
    	/**
    	 * Constructs a panel showing given alarm.
    	 * 
    	 * @param alarmData
    	 *            Map:
    	 *            <ul>
    	 *            <li>key - column name (String)</li>
    	 *            <li>value - column's value (DataItem)</li>
    	 *            </ul>
    	 * @param translator
    	 *            the translator used.
    	 * @return
    	 */
    	public static JPanel constructAlarmPanel(Map alarmData,
    			TranslatorInterface translator) {
    		JPanel alarmsPanel = new JPanel(new GridBagLayout());
    		alarmsPanel.setBorder(BorderFactory.createTitledBorder(""));
    		int dcnY = 0;
    
    		// alarmId
    		dcnY += 1;
    		alarmsPanel
    				.add(new FieldLabel(alarmId,
    						translator), new GridBagConstraints(0, dcnY, 1, 1, 0,
    						0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    						insets, 0, 0));
    		JTextField alarmIdTf = new JTextField(20);
    		DataItem alarmId = (DataItem) alarmData
    				.get(alarmId);
    		alarmIdTf.setText(alarmId == null ? "" : alarmId.getValue());
    		alarmIdTf.setEnabled(false);
    		alarmsPanel
    				.add(alarmIdTf, new GridBagConstraints(1, dcnY, 1, 1, 0, 0,
    						GridBagConstraints.WEST, GridBagConstraints.NONE,
    						insets, 0, 0));
    return alarmsPanel;
    	}
    
    }
    Hope you refer to these :)

    Thanks

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    problem is that sometime in a tab (example with key "1") it isn't display the Jpanel
    What does happen then? Do you mean when you press a tab on the JTabbedPane?

  5. #5
    Ravanelly is offline Member
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Default

    Yes, when I click tab (JTabbedPane)"1" for example I have a Jpanel who is empty like in picture attach and on others tabs"2", "3"..everything is ok, is not empty

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    when I click tab (JTabbedPane)"1" for example I have a Jpanel who is empty
    The question then is why is the panel for tab "1" empty?
    Have you tried putting something in that panel that is sure to show?
    Have you tried creating a special one panel screen using the panel for "1" to see if it shows OK?

  7. #7
    Ravanelly is offline Member
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Default

    Yes is have something, is like others tabs "2" or "3"....
    Sometime is empty and sometime it isn't...this is way I'm asking :D...it takes information from ShowAlarmsDialogHelper.constructAlarmPanel like others tabs...
    I don't know why sometime is empty and sometime not?
    It have some connection with threads or with SwingUtilities.invokeLater?I don't know much about it...or how to look to see?I've try but without luck.

    Thanks

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    You'll have to try to debug what is happening. What have you done so far?
    We can't help you without a working program that demos the problem.

Similar Threads

  1. Cannot display in JPanel
    By atch in forum New To Java
    Replies: 2
    Last Post: 02-05-2010, 02:21 PM
  2. How to add JFrame inside JPanel
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 8
    Last Post: 12-13-2009, 08:41 PM
  3. display a new jpanel in an applet
    By toymachiner62 in forum Java Applets
    Replies: 6
    Last Post: 10-18-2009, 11:10 PM
  4. can't get anything to display on my JPanel
    By v1nsai in forum AWT / Swing
    Replies: 9
    Last Post: 08-25-2009, 08:25 AM
  5. Display output in Jframe or JPanel
    By rammurugesan in forum AWT / Swing
    Replies: 12
    Last Post: 04-14-2009, 01:45 PM

Posting Permissions

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