I have a long list of data to be presented in on the jtabbedpanel, on scrolling down for the data the tabbed panel name at the top will not be visible .How can i make the tabbed panel tabs visible at the top even on scrolling down?
Can anyone help on how i can fix this , or mention some posts regarding the same ?
Thanks in advance .
From the sounds of it, you are adding the JTabbedPane to the JScrollPane.
Instead, add each tab's component to a JScrollPane and then add this (the scroll pane) as the tab...
ie...
JScrollPane scrollPane = new JScrollPane(reallyLargePane);
tabbedPane.addTab("Another tab", scrollPane);
Related
I have added some collapsible panels to my JScrollpane. When they are extended, the JScrollpane is not allowing me to scroll. Below is the code I'm using.
JScrollPane scrollPane = new JScrollPane(makeContentForPropertiesWindow());
propertiesTabDoc.add(scrollPane,BorderLayout.CENTER);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
The makeContentForPropertiesWindow method populates the collapsible panels. I've used GridLAyout there. I've also tried FlowLayout and BorderLAyout as well. All result in the same output. Currently below is how it looks.
What am I doing wrong here? Why is it not allowing me to scroll though the vertical area is full? Please advice.
I'm actually having no problem when dealing with the JScrollPane with JTextArea...
But here... I have a JPanel. And I wanted to use Scroll on it.
Take a look on my JPanel here Image Preview.
I wonder how to do it in netbeans. I think I should do a bit of customized coding.
So, I tried to do like this;
1) Right Click on jPanel2, Customize Code.
2) Using This modified code;
Initialization Code:
jPanel2 = new javax.swing.JPanel();
scrb = new javax.swing.JScrollPane(jPanel2);
// Code of sub-components - not shown here
// Layout setup code - not shown here
scrb.setPreferredSize(jPanel2.getPreferredSize());
jPanel1.add(jPanel2, "card2");
Variable Declaration Code:
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane scrb;
Then re-run my Project again....
but,... sigh. THe Scroll didn't came up into the running app.
Is there anything I forget over here?
I tried to manipulate the Size of the jPanel2, but hence not work....
The Scroll didn't appeared.
The problem is in this line:
jPanel1.add(jPanel2, "card2");
Instead of this write this:
jPanel1.add(scrb, "card2");
What you are doing is adding jPnael2 to a scrollpant but then instead of adding that scrollpane to jPanel1 you add jPanel2 to jPanel1 so scrollPane doesn't even come to picture.
Try adding the scrb to jpanel1.
Here's a nice tutorial in scroll panes;
http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html
In addition to the other suggestions to add the scrollpane to the panel, I'm not sure if it will work because of the following line of code:
scrb.setPreferredSize(jPanel2.getPreferredSize());
Scrollbars only appear when the preferred size of the component added to the the scrollpane is greater than the size of the scrollpane. So if you layout manager respects the preferred size of the components this condition will never be true.
If you are using NetBeans IDE, it is better to use GUI designer to create scroll pane. Use the below steps to implement a scroll pane:
1. In Netbeans GUI editor, select all panels which requires scroll pane using CTRL+left click
2. Right click on the highlighted panels, select the option 'Enclose in' -> Scroll Pane. This will add a scroll pane for the selected panels.
3. If there are other elements than Panel(say JTree), select all the elements ->Enclose in ->Panel. Then enlose the new parent panel to scroll pane
4. Make sure that 'Auto Resizing' is turned on for the selected parent panel(Right click on panel -> Auto resizing -> Tick both Horizontal and vertical)
I have been trying to use JScrollPane with my applet, but it doesn't work. I have a JPanel to which I add 20 buttons, and I want to be able to scroll up and down this JPanel. Instead, the scrollbars do not appear. When I use setPreferredSize they still did not appear even though only about 3 of the buttons are being displayed and the rest are cut off. If I do not use setPreferredSize, there might as well not be any scrollbars because I have to make the window big enough to see all of the buttons. If I try to make the scrollbars always visible, they appear but do nothing. I tried the exact same code with JFrame instead of Applet, and it works fine, but I need it to be an applet. Is JScrollPane incompatible with applets? (Note: I tried to use an outer JPanel and add the scrollable panel to it, but it changed nothing). Changing the layouts also doesn't fix the problem. I have attached a simplified version of my code, but it displays the same errors.
Here is the code I have:
JPanel scrollPanel = new JPanel();
scrollPanel.setLayout(new BoxLayout(scrollPanel, BoxLayout.PAGE_AXIS));
JScrollPane scroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
for (int i = 0; i < 20; i++) scrollPanel.add(new JButton("Button " + i));
add(scrollPanel);
validate();
You never all the panel to the scroll pane
You never add the scroll pane to the applet
The basic code should be:
JScrollPane scrollPane = new JScrollPane(...);
scrollPane.setViewportView( scrollPanel );
add( scrollPane );
You are adding components to a Panel so you shouldn't expect to see a scroll pane wihout showing the scrollpane. What you want to do is then add that panel to a scrollpane which would be added to ur main container.
From your code, i think your problem is
add(scrollPanel);
your should be doing this
add(scroll);`
This is because you only added the panel to the frame which does not contain any scrollpane. Since you have added the panel unto the scrollpane, you should add the scrollpane and not the panel to the main container.
It sounds like you are using Swing components (JScrollPane, JPanel, ...) in an AWT container (Applet). Try using JApplet instead.
I need help. I have one panel which can need to have width 1000px. I need to add lot of buttons with different size ( I add with flow layout and it works fine). Problem is that I have height on screen example 500px but when I add buttons panel has bigger size. How to add scrollbar to panel ?
Add your panel to scrollpane and add that pane where you are adding your panel instead of panel
JScrollPane jScrollPane = new JScrollPane(panel);
I'm building a Swing application in Java using NetBeans and I have a problem with layout. My main frame contains a JScrollPane which contains a JPanel called contentPanel which in turn contains a JPanel called listPanel. The listPanel is empty when the program starts, but when the user interacts with the program an unpredictable number of smaller JPanels are added to it. I've used the NetBeans GUI-builder to snap the top edge of listPanel to the top of contentPanel, and the same with the bottom edges.
The problem I have is that when more components are added to listPanel the vertical scrollbar doesen't appear on my scrollpane. The verticalScrollBarPolicy of my scrollpane is set to AS_NEEDED and its viewportView is set to contentPanel. What I think I need to do is to make contentPanel grow when more items are added to listPanel.
The problem I have is that when more components are added to listPanel the vertical scrollbar doesen't appear on my scrollpane.
The scrollbar will appear when the preferred size of the component added to the scrollpane is greater than the size of the scrollpane. When you add components dynamically you need to tell the scrollpane something has changed. So you basic code should be:
panel.add( subPanel );
panel.revalidate();
Or, because you are adding a panel to the sub panel, you may need to revalidate the scrollpane (I don't remember):
panel.add( subPanel );
scrollPane.revalidate();
The key is the revalidate() which tell the layout manager to recalculate its size.
Use a different LayoutManager. One that will allow for vertical growth like BoxLayout. Also remember that you can use multiple layouts and nest them inside of each other for different effects.