File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JScrollPane inside JTabbedPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollPane inside JTabbedPane" Watch "JScrollPane inside JTabbedPane" New topic
Author

JScrollPane inside JTabbedPane

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Hi,
When I put JScrollPane inside JTabbedPane the screen looks messed up. All I see is very small JScrollPane in the center of the viewable are. If I replace JScrollPane with a regular JPanel, everything works fine. What I want to accomplish is to make JScrollPane behave as it should inside JTabbedPane, so that the whole space occupied by JTabbedPane's viewable are is scrollable by JScrollPane.
Here is part of code:
=====================
JPanel scrollPanel = new JPanel();
scrollPanel.setLayout(gbl);
scrollPanel.setPreferredSize(new Dimension(500,500));
//JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZON
TAL_SCROLLBAR_NEVER);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new Dimension(500,500));
...
...
...
gbc.gridx = 0;
gbc.gridy = 19;
gbc.anchor = GridBagConstraints.WEST;
gbl.setConstraints(box17,gbc);
scrollPanel.add(box17);
scrollPane.setViewportView(scrollPanel);
scrollPane.add(scrollPanel);
scrollPane.setViewportView(scrollPanel);
screen.add(scrollPane); **

** screen is my JTabbedPane().


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Greg Brouelette
Ranch Hand

Joined: Jan 23, 2002
Posts: 144
Alex:
My gut feeling is that the problem is with the gridbag layout rather than with your scroll pane. Just for fun, try doing what you need to do using a BorderLayout or a GridLayout(1,1) and see if the scroll pane shows up correctly.
After a very long project where I was forced to use the DirtBagLayou. . .excuse me . . . I meant "GridBagLayout" layout manager I've come to believe that there are very few times when a GridBagLayout is needed. With very few exceptions I've been able to do everything I need with BorderLayout, GridLayout, and FlowLayout by putting panels inside panels.


For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thanks,
actually, there was a problem with how I was putting everything together. This is what I got from expert-exchange.com :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TabbedPaneDemo extends JPanel {
public TabbedPaneDemo() {
ImageIcon icon = new ImageIcon("images/middle.gif");
JTabbedPane tabbedPane = new JTabbedPane();
Component panel1 = makeTextPanel("Blah");
tabbedPane.addTab("One", icon, panel1, "Does nothing");
tabbedPane.setSelectedIndex(0);

Component panel4 = makePanel();
tabbedPane.addTab("Two", icon, panel4, "Does nothing at all");
//Add the tabbed pane to this panel.
setLayout(new GridLayout(1, 1));
add(tabbedPane);
}
protected Component makeTextPanel(String text) {
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
protected Component makePanel() {
JPanel panel = new JPanel(false);
JEditorPane jEdit = new JEditorPane();
JScrollPane jScrollPane1 = new JScrollPane();
jScrollPane1.getViewport().add(jEdit, null);
panel.add(jScrollPane1, null);
panel.setLayout(new GridLayout(1, 1));
panel.add(jScrollPane1);
return panel;
}
public static void main(String[] args) {
JFrame frame = new JFrame("TabbedPaneDemo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
frame.getContentPane().add(new TabbedPaneDemo(),
BorderLayout.CENTER);
frame.setSize(400, 125);
frame.setVisible(true);
}
}
I tried it, works for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JScrollPane inside JTabbedPane
 
Similar Threads
TextArea and ScollPane
JTextPane inside JScrollPane
Panel in ScrollPane
Swing Graphics and JPanel setPrefrerredSize
Dynamically changing contents of a scrollpane, doesn't display?