hai,

is it possible to loading of tabs in jtabedpane dyanamically in java..

that means i have frame that consinting of one tabbedpane..

in that i have 10 tabs and in each tab consting of another tabbedpane and in that each tabbedpane has 4 tabs and each tab consisting buttons and textfields......

when i login into my project the next frame takes more time to visible....

this is happens why because i have more tabbedpanes in my frame so that it takes the lot's of time to visible..

my question is..

is it possible to load tabs content dynamically when i click the tab in tabbedpane.....

or is it possible to load tabbedpanes fastly......????????

Recommended Answers

All 5 Replies

I'll bet your problem is somewhere else or you have a lot and lot and a lot of data in each of your pane.

If it is the case, yes you can.
Just add all your pane (JPanel I presume) empty
Have a Listener to inform you when a Tab change
In that case, have a flag for each pane signaling if it is filled or not
If it is not filled fill it at that moment

But again, your problem must be somewhere else

Just wrote a little test program:

a JTabbedPane with 26 tabs
each of these tab contains another JTabbedPane with 26 panes
each pane is consists of a JPanel with 100 JLabel

total load time on my AMD Laptop 3 years old: 2.7 seconds

import javax.swing.*;
import java.awt.*;
/*
 * Test the preformance of JTabbedPane
 */
public class TabAndTab extends JTabbedPane {

	// a JTabbedPane with 26 panes containing 26 JTabbedPane containing 26 JPanel
	TabAndTab() {
		for(char i = 'A'; i <= 'Z'; ++i) {
			addTab("" + i, new Tab26());
		}
	}
	/*
	 * This class generates a TabbedPane with 26 tab (A-Z)
	 * Each of them containing a JPanel with 100 JLabel
	 */
	class Tab26 extends JTabbedPane {
		Tab26() {
			for(char i = 'A'; i <= 'Z'; ++i) {
				JPanel p = new JPanel(new GridLayout(10, 10));
				for(int j = 0; j < 100; ++j) {
					JLabel label = new JLabel("" + j);
					label.setHorizontalAlignment(SwingConstants.CENTER);
					p.add(label);
				}
				this.addTab("" + i, p);
			}
		}
	}
	
	public static void main(String[] args) {
		JFrame f = new JFrame("TabbedPane performance");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setBounds(10, 10, 700, 400);
		long from = System.currentTimeMillis();
		f.add(new TabAndTab());
		f.setVisible(true);
		long now = System.currentTimeMillis();
		System.out.println("Load time: " + (now-from));
		
	}
}
Member Avatar for vjcagay

your codes may be right,,,,
but as we all know that Java, being a high-level programming language, run more slowly than any other languages,
this is because java codes are interpreted on a virtual machine before it can be read by the system,
that may be the case,, so the more data you have inside your frame, the more data the virtual machine will interpret, the more time it will consume,,,
i also think that your hardware also matters, the more speedy your hardware is, the less the slowness of Java will be the issue.
:)

@vincentjohn:
That is just ridiculous. Please read up on the JVM and modern just-in-time compilers before you start tossing around nonsense like that.

The OP did not even supply enough information to begin to know why it is "slower" and how he can load his panes "fastly". My guess would be some recursive layout issues with how he is building the UI dynamically, but without code or more explanation, it's impossible to say.

Member Avatar for vjcagay

maybe you're right though,,
thanks..
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.