Replace tab with icon in JTabbedPane - java

Can someone give me advice on how can I the change tab (only in the tab itself, not the tab's content area) in JTabbedPane to an icon. It is possible to set another icon when the tab is selected, another icon on mouse over, and another icon when tab isn't selected. I'd like to have this icon on full tab width and height under the text, similar like when one replaces a whole button with an image.

Take a look at setTabComponent, this will allow you to supply a custom renderer for that tab
You would then need to monitor changes to the tab selection via the changeListener, when the tab changes, you would use the getTabComponentAt method to get the renderer and update it

Related

Change the selected item

I have a JEditorPane and when I press ctr + space it makes visible a JScrollPane but because the editor pane is still selected is there any way to set the selected Item to be another?
(Selected is when you press a JTextArea and you can edit it so is selected the text area.)
Like I want to when I press ctr + space it appears the scroll pane and it selected so I just need to press an arrow to scroll.
You need to call requestFocus() on the JComponent you want "selected".
Edit: From the documentation for JComponent#requestFocus:
Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow(boolean).
So maybe give requestFocusInWindow() a try as well.

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

What is the name of this Swing component?

I want to put one toolbar type component in which there will be one button which when pressed the toolbar should expand, size of the form increases and it contains some components like text area and label that user can see and once again when the button is pressed the toolbar is minimized and the size of the form decreases.
Can anybody tell me how to accomplish this?
e.g; like in windows 7 in my computer there is one toolbar called "Hard Disk Drives". When we press on it it shows all the drives and when we again press it it hides it.
SwingX has a collapsible panel control that I think should do what you want.
Also take a look at How to have Collapsable/Expandable JPanel in Java Swing.
Some alternatives:
You can add a JButon to a JToolBar. In your button's ActionListener, open a JOptionPane containing your components. This example illustrates some possibilities.
For a more advanced view, consider Outline, illustrated here.

Adding 2 different menu bars in java

I'm creating two menu bar 1st menu bar is for background color & 2nd is for text color.the application contains text component where user can type text.when user press either of menu scroll bar are shown on screen.for red,blue,green, color component the user can adjust the position of scroll bar,on pressing "OK" button the foreground or background of text component on frame changes according to the menu choice.
One possibility is to create an MDI (one parent window, with an internal child window for each document). See: How to Use Internal Frames. The JDesktopPane and each JInternalWindow can have their own menus.
Two menus bars sounds awkward. Usually a single menu bar is more than enough to handle. Have you considered a popup menu instead for the second set of menus? If you still insist on adding multiple menu bars to a frame, consider changing their position for example use BorderLayout.SOUTH on one of them.

How do I make dynamic windows in Swing?

I have a general question. I would like to have a window containing some buttons, radio buttons, text fields and so on. So, user can do something (write text, select options and press buttons). As the result of the user activity window should change it structure/appearance some element should disappear and some appear.
How do I program such "updates"? Should I close an old window and open a new one or I can modify content of window without closing it?
After adding your components or such, calling revalidate() on your container will do the updates

Categories

Resources