Change label of current panel in tabbed pane - java

I need to change the label of the currently selected tab in tabbed pane.
It is for when the user saves the file the change must be reflected in the label of the current panel in the tabbed pane.
Tried a few things like:
tabbedPane.setSelectedComponent(this.panel1.setName(name));
but no good

A very simple line of java code will do this:
tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), newTabLabel);
This could be easily figured out from the Java API for JTabbedPane.

Related

Create Custom Look and Feel for a JTabbedPane

I am trying to create a JTabbedPane that will always fill the top part of the Component with the tabs. Like so:
And this is how it look now:
And the code for this part:
JTabbedPane tab = new JTabbedPane();
tab.addTab("Items", items);
tab.addTab("Categories", categories);
setContentPane(tab);
//Also tried to create a JTabbedPane class and see if i could remove the labels and manually add two buttons to the top but without success.
I want the tabs to use up as much space as possible without actually shrinking the content of the panels.
So could anyone tell me how to customize the JTabbedPane, the look and feed or just the tabs themselves in order to do that.
The easiest approach is probably to create your own component:
Create a "main" panel that uses a BorderLayout.
Create a panel that uses a GridLayout and add your buttons to this panel. Then add this panel to the "main" panel using BorderLayout.PAGE_START. Each of these button will display a specific panel when clicked.
Create a second panel that uses a CardLayout. Add this panel to the "main" panel using BorderLayout.CENTER. Each of these panels will represent a tab.
The other option is to look at the TabbedPaneUI and find a method that paints each tab and modify the code for your requirement.

Is there a way to make the tabs in tab pane more thick in netbeans?

Im using netbeans 7.4.
Im going to create a JFrame using nebeans forms which contain a tab pane.
I have set the tab placement property to "left" and I have added a few tabs.
But the tabs are so thin. i need to increase the area of a tab(not the JPanel inside the tab pane but the tabs (which contain the titles of tabs)).
Can someone please explain me how can i change tabs' appearance and the area(height or thicknes)?
this is like what i need
http://i.stack.imgur.com/lAo4f.jpg

Stacking over input panels in Netbeans WYSIWYG editor?

I'm trying to put a JButton in the WYSIWYG GUI editor in Netbeans at the center of a wheel of buttons I made around an input panel. The input panel is hidden in the program (specified by a user in an XML file) and the JButton should just be at the center of the wheel. I can't figure out how to do that because actually putting it in on top of the input panel in the WYSIWYG editor just puts it in the input panel and it is therefore hidden when when the code is executed. Is it possible to view the "layers" in the editor and put the button in "under" the input panel so that it won't be hidden along with the panel?
The only effective solution I could find was to modify a gridbag constraints object and manually insert the button in the code after the panel was hidden at runtime.

Make a particular component visible in a Scrollable JPanel

I have a scrollable JPanel in which are added many Editor Panes (having their respective Scroll Pane) in Box layout (Vertical Axis).
My problem is that on clicking a particular button I want a particular Editor Pane to gain focus and also be visible on the screen.
I am unable to make that Editor pane visible.
I tried
scrollRectToVisible(jScrollPane5.getVisibleRect()); //It did nothing !
I also tried
scroller.setViewportView(jScrollPane5); // It made the particular editor pane occupy the entire panel !
Kindly suggest what to do ?
Thanks.
Invoke scrollRectToVisible() on the "Editor Pane" that you want to be visible in the scroll pane.
Also, after clicking on the button it will have focus so you need to use requestFocusInWindow() on the edtitor pane that you want to have focus.
You can also check out Scrolling a Form which will do this for you whenever any component in the scroll pane gets focus.
scrollRectToVisible(theWantedEditorPane.getBounds())

How do I add a menubar to a tabbed pane?

Is it possible to add a menubar to one of the windows in a tabbed pane? And is a frame the only container which can have a menubar?
As Suraj mentioned, you can force the issue as as they are both, both components and containers however you will have to do the extra work to organize it in your pane's layout along with the rest of the components in the pane -- unlike with a JFrame which has methods to support it outright (setJMenuBar and you're outta there). Normally, when added to a JFrame, the JMenuBar is not in the content pane, it is in a layered pane which contains both the menu bar and the content pane below it.
You might also want to consider using a JToolBar which is very flexible (more easily customized) and has some optional built-in goodies like being separable/dockable.
Though you can directly add a JMenubar in to a JtabbedPane as both are JComponents. But it wont look nice(usable), if you have tried it.
I would suggest to subclass BasicTabbedPaneUI and override installComponents(), there you can add you JmenuBar at the top or wherever you want.
Is it possible to add a menubar to one
of the windows in a tabbed pane?
What problem did you have when you tried to do this?
If you need more help post your SSCCE showing the problem.

Categories

Resources