Split labels in JTabbedPane

I need to change my label's distribution on a JTabbedPane.

I have this:

enter image description here And I want to do this: enter image description here Can someone help me?

I post the code below:

 tabbedResultsPane = new JTabbedPane(SwingConstants.TOP);

     JPanel featurePanel = new JPanel(new GridLayout(TOTAL_FEATURES, 2, 3, 3));  
     estadoScroll = new JScrollPane(featurePanel,
                      JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                      JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        lblFeatureHdr = new JLabel[TOTAL_FEATURES];
        lblFeature = new JLabel[TOTAL_FEATURES];
        for(int i=0; i<TOTAL_FEATURES; i++)
        {
           lblFeatureHdr[i] = new JLabel(strHeader[i], JLabel.RIGHT);
           lblFeatureHdr[i].setOpaque(true);  
           lblFeatureHdr[i].setBackground(new Color(220,255,220));//.lightGray);

           lblFeature[i] = new JLabel("", JLabel.LEFT);
           lblFeature[i].setForeground(Color.blue);// black); 

           featurePanel.add(lblFeatureHdr[i]);
           featurePanel.add(lblFeature[i]);                
        }            

Upvotes: 0

Views: 99

Answers (1)

StanislavL
StanislavL

Reputation: 57421

Define 4 columns GridLayout (rather than 2 columns you have).

and correct your code yo add 2 more labels for each row.

for(int i=0; i<TOTAL_FEATURES; i++)
    {
       lblFeatureHdr[i] = new JLabel(strHeader[i], JLabel.RIGHT);
       lblFeatureHdr[i].setOpaque(true);  
       lblFeatureHdr[i].setBackground(new Color(220,255,220));//.lightGray);

       lblFeature[i] = new JLabel("", JLabel.LEFT);
       lblFeature[i].setForeground(Color.blue);// black); 

       featurePanel.add(lblFeatureHdr[i]);
       featurePanel.add(lblFeature[i]);  
       // add 2 more lables to the same row    
       JLabel l=new JLabel(strHeader[i], JLabel.RIGHT);
       l.setBackground(new Color(220,255,220));//.lightGray);          
       featurePanel.add(l);
       featurePanel.add(new JLabel("", JLabel.LEFT));                
    }            

Upvotes: 2

Related Questions