Make a particular component visible in a Scrollable JPanel - java

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())

Related

JScrollPane in JTables

I wonder if you guys had problem such if you got some JPanel which got his own JScrollPane and in your panel you are using a lot of JTables with their own JScrollPanes, there is a problem to scroll up/down your panel?
I mean when your mouse is on viewport of some table, then JScrollPane of JTable is listening on scroll, so when I got many JTables I am able to scroll only in a few places of the panel, it's so annoying...
Are there some functions which will send my scroll event to parent JPanel JScrollPane when the JTable scroll is even not shown? I mean I want to disable JScrollPane whenever some JTable don't need to use scroll (when it is hidden, cause there are too less records).
Yes, JTable understands several named scrolling actions, listed below. They are normally used in key bindings, but you can evoke them yourself, as shown in this related example that commandeers the actions defined for a scroll pane.
Addendum: In outline, get the named action from the component's action map:
Action action = table.getActionMap().get(name);
Evoke the action by name when needed:
action.actionPerformed(new ActionEvent(table, 0, name));
Scrolling related action names for JTable:
scrollDownChangeSelection
scrollDownExtendSelection
scrollLeftChangeSelection
scrollLeftExtendSelection
scrollRightChangeSelection
scrollRightExtendSelection
scrollUpChangeSelection
scrollUpExtendSelection

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.

Change label of current panel in tabbed pane

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.

Replace tab with icon in JTabbedPane

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

Java: How can I disable clicking on a panel while showing dialog?

I want to disable clicking on the background panel or frame while showing a dialogue. And I want the dialogue to appear on top of this panel or frame constantly until it is closed.
How can I do this?
Make Dialog/JDialog modal by calling dialog.setModal(true);. This will solve both issues of clicking background panel and remaining on top of panel.
It seems like this method is obsolete so better you should use dialog.setModalityType(Dialog.ModalityType type)
You can use JOptionPane for the message dialog.

Categories

Resources