Wednesday, May 31, 2017

How to insert a tab into JTabbedPane instead of adding it to the end

public class TabTest { 
      public static void main(String[] args) { 
            JTabbedPane pane = new JTabbedPane(); 

            JLabel fruitLabel = new JLabel(new ImageIcon("fruit.gif"));
            pane.add(fruitLabel);

            String[] birds = {"Sparrow", "Pigeon", "Sea gull", "Eagle", "Parrot"};
            JList<String> birdList = new JList<>(birds);
            pane.add(birdList);

            int index = 1;

            JPanel sportTeamPane = new JPanel();
            sportTeamPane.add(new JTextArea("Here's the description of the team:"));
            //Add the component to a specific position instead of to the end
            pane.add(sportTeamPane, index);

            JTable table = new JTable(myPopulationTableModel);
            JScrollPane sp = new JScrollPane(table);
             //Insert the component to a specific position instead of to the end
            pane.insertTab("Population", new ImageIcon("population.gif"), sp, "population tab", index); 
      } 
}

---------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment