I'm looking for a way to clone (duplicate) a whole tab (the selected one) in a JTabbedPane. Every time I take the tabwith getSelectedComponent() and add it to the pane, the title of the tab disapnö rs and I get no second tab. But there is no exception.
I tried to copy the currently selected tab. Each tab is a JPanel with a simple JTable on it and I want to get the selected tab two times.
As far as I know, the same swing component can't appear in multiple places in your GUI, so you would actually have to create new instances of all your UI elements for the "copied" tab and set their values to the same values of the first tab / connect them to the same domain objects.
In Swings, a component can be added to only one container. Adding it again to another container will have no effect.
Related
I'm trying to add an applet to one of my tabs, but each time I try to add it to a certain tab, it's creating a new tab.
I have already made the tabbed pane using netbeans, added panels to both of the tabs and tried to replace the panel with my applet panel and it's not working correctly. My questions is how can I refer to the "Game" tab and add the applet to that panel?
https://dl.dropbox.com/s/q0lfuz9cxp757n8/Screenshot%202014-07-13%2001.06.42.png
Here's what I'm trying
TabbedPane tabbedPane = new TabbedPane();
tabbedPane.gameTab.add(gamePanel);
And it keeps creating a new tab as seen in the image, but I'm trying to add the gamePanel to the existing "Game" tab.
First of all you don't want to keep creating a new JTabbedPane. You want to update the existing tabbed pane.
Read the JTabbedPane API. There are several approaches you could use:
1) Use the remove(...) method to remove the current tab, then use the add(...) method to add a new tab. The API allows you to add a tab to the end or at a specific index. This is probably the easiest.
2) Use the getComponentAt(...) method to get the panel that was added to a specific table. Then you can add any component to this panel, assuming you have a proper layout.
In both cases the question is why isn't the applet added when you initially create the tab?
Is it possible to create panel with dynamic added tabs in GWT using TabPanel or TabLayoutPanel.
My requirements:
First tab is not closeable and has a celltable.
When I select row in the celltable, new tab is created.
Newly created tab can be closed.
My question:
How to create this architecture in GWT using MVP style and UiBinder?
Why not? Even if you get some problem in GWT, you always can dive into level below to javascript and make exactly what you need.
Any panel can be dinamically changed. If it is layout panel then you can forceLayout() it at any moment. You can add() or insert() new items to panel and use different selfmade widgets for tabs (you have a lot of possibilities how to add or insert: add(Widget child, Widget tab) or add(Widget child, SafeHtml html)).
Here is an example how it made with ExtGWT, logic is identical but you will have to made widgets for your tabs (that can be closed and not).
I've developed a simple Swing GUI to allow the user to edit the data of my application. The UI is rather simple:
A JFrame that contains a JTabbedPane.
Each of the tabs consists of one subclass of JPanel that offers tools to edit an aspect of the data.
The data itself is contained in one object and a reference is passed to each of the JPanels.
But there's a problem: I need to sync the different JPanels.
For example, the data object stores a list of persons and a list of tasks.
One JPanel allows the user to edit the persons. He can create new Persons and delete existing ones.
The second JPanel allows the user to assign persons to tasks.
Both JPanels are initialized when they are first opened. The components are created and the layout is set. Now the user can start to work with the UI.
He opens the first tab of the JTabbedPane and creates a the first Person.
He opens the second tab. The Components of the second tab are initialized and list the one person that is available. He assigns a task.
He returns to the first tab and creates a second person.
He switches back to the second tab to deal with the new person.
But the second tab and the JPanel it contains have already been initialized. The user will not see the second person, unless the JPanel is updated. I have implemented a custom update method on my JPanel subclass for tab 2. But how do I call it ?
I need the Swing event that is fired on a Component, when it is redrawn.
Actually updating the second panel when the first gets redrawn is bad idea even if you manage to find the event that gets fired. This would cause the second panel to be updated on every redraw of the first panel, regardless of wether the redraw means that the undelying data has changed or not (think about unsaved data).
You should make the data your tabs maipulate Observable (or Subject from Observer Pattern). Then each tab can react to changes in the data instead of changes in other tabs. This will reduce the time of updates to only when it is really needed and also will decouple the tabs from one another.
The data may repesent changes by firing PropertyChangeEvent's. These in turn should trigger Controller actions as suggested by Gilber Le Blanc in the comments.
I'm looking for a component like "JTabbedPane" in which I can design each tab separately and easily but I don't want the little square buttons with tab names in runtime! Instead, I want to activate each tab panel in my code. In fact, I want to have multiple "JPanel"s with same size and location (they have complete overlap) and I set visibility of each them manually in my code but the most importing thing is that I want to design each panel as easy as possible (like clicking on the tab names in design-time).
You could use CardLayout here to create your own overlapping panels as you have described. The visibility of each panel can be programmatically changed.
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......????????
It should be quick to load tab panes. What must be taking a moment is the content in the tabs. You can create tabs dynamically with the same way you create them when you build the GUI initially. My guess is that the content is your real problem. Depending on what that is you can load some items on threads other than the EDT and then come back. (Look into SwingWorker).
You can make use of SwingUtilities.invokeLater to push the creation of your inner tab panes to occur after initially displaying your tab pane..
Create the outer tab pane
Create stub panels for all tabs in the outer pane - this will put placeholders in for your tabs, making it look to the user that they have already been created.
Create content for the first tab.
Iterate over tabs 2 to n, creating Runnable instances that setup the content of the tabs, including their inner tab panes. Use these Runnable instances as the param to SwingUtilities.invokeLater. This will put these actions at the end of the EDT, so they will be performed after the current action has completed.
Complete the setup of your outer tab pane, adding it to your JFrame or other container and setting it visible.