ScrollBars not showing up for the JPanel [urgent]

Hi,

I have a frame in which i have two nested split panes i.e one horizontal splitpane and in that i am having one more split pane on the right side and a JTree on the left side.In the second split pane (which is a vertical split) ,as a top component , i am setting a JScrollPane in which i am trying to display a JPanel which is having a lot of swing components in it.I want to see the scroll bars for this panel so that i can see all the components.Do i have to implement Scrollable interface for this panel to scroll in the ScrollPane.I don't know how to implement Scrollable interface.Can some body help me in resolving this?This is some what urgent.Any help will be highly appreciated.

Thanks in advance.

Ashok

[748 byte] By [ashok1000] at [2007-9-26 3:10:22]
# 1

please try this code and tell me more about your problem, I dont understand it very well. You don t need implement the Scrolleable interface...

import java.awt.*;

import javax.swing.*;

public class Frame1 extends JFrame {

JSplitPane jSplitPane1 = new JSplitPane();

JSplitPane jSplitPane2 = new JSplitPane();

JScrollPane jScrollPane1 = new JScrollPane();

JPanel jPanel1 = new JPanel();

public Frame1() {

try {

jbInit();

}

catch(Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

Frame1 frame1 = new Frame1();

frame1.setSize(100,100);

frame1.show();

}

private void jbInit() throws Exception {

jSplitPane1.setRightComponent(jSplitPane2);

jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);

jSplitPane2.setTopComponent(jScrollPane1);

this.getContentPane().add(jSplitPane1, BorderLayout.CENTER);

jSplitPane1.add(jSplitPane2, JSplitPane.BOTTOM);

jScrollPane1.getViewport().add(jPanel1, null);

for(int i=0;i<20;i++)

jPanel1.add(new JButton(i+"", null));

}

}

eormeno at 2007-6-29 11:16:50 > top of Java-index,Archived Forums,Swing...
# 2

No you don't need to implement anything.

Simply add the components you want onto the JPanel and then

call

scrollPane.setViewPort(panel);

Alternatively you can choose to add the panel to the JScrollPane when you construct it.

scrollPane = new JScrollPane(panel) or

scrollPane = new JScrollPane(panel , vsbPolicy, hsbPolicy)

hsb/vsb = int hori/ver scrollbar policy

and can take values

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS

(Similarly with VERTICAL)

shirish_wagh at 2007-6-29 11:16:50 > top of Java-index,Archived Forums,Swing...
# 3

That's scrollPane.setViewportView(panel), not scrollPane.setViewPort(panel).

Do describe the problem more. Are you already able to see all the components held by the JPanel? If so, the scrollbars will not appear unless you have set the scrollbar policies to ~ALWAYS as described in the previous message.

earljavadev at 2007-6-29 11:16:50 > top of Java-index,Archived Forums,Swing...
# 4

Thank you all for your replies.I added the scroll bar policy.The scroll bars are showing up but the components inside the Panel are not moving.I want the components to move when i am scrolling.Here is my code.In the code SeriesDescPanel, SeriesDescMapPanel are sub classes of JPanel.I am using null layout to add the components to these panels.

public class MainWindow extends JFrame implements TreeExpansionListener

{

public MainWindow()

throws RemoteException

{

// This code is automatically generated by Visual Cafe when you add

// components to the visual environment. It instantiates and initializes

// the components. To modify the code, only use code syntax that matches

// what Visual Cafe can generate, or Visual Cafe may be unable to back

// parse your Java file into its visual environment.

//{{INIT_CONTROLS

setJMenuBar(menuBar);

setTitle("Series Maintenance");

getContentPane().setLayout(new BorderLayout(0,0));

setSize(667,478);

setVisible(false);

JSplitPane1.setDividerSize(1);

JSplitPane1.setOneTouchExpandable(true);

getContentPane().add(BorderLayout.CENTER, JSplitPane1);

seriesMenu.setText("Series");

seriesMenu.setActionCommand("Series");

menuBar.add(seriesMenu);

newSeriesGroupMenuItem.setText("New Series Group");

newSeriesGroupMenuItem.setActionCommand("New Series Group");

seriesMenu.add(newSeriesGroupMenuItem);

newSeriesMenuItem.setText("New Series");

newSeriesMenuItem.setActionCommand("New Series");

seriesMenu.add(newSeriesMenuItem);

seriesMenu.add(JSeparator1);

serachMenuItem.setText("Search");

serachMenuItem.setActionCommand("Search");

seriesMenu.add(serachMenuItem);

seriesMenu.add(JSeparator2);

saveMenuItem.setText("Save");

saveMenuItem.setActionCommand("Save");

seriesMenu.add(saveMenuItem);

seriesMenu.add(JSeparator3);

exitMenuItem.setText("Exit");

exitMenuItem.setActionCommand("Exit");

seriesMenu.add(exitMenuItem);

adminMenu.setText("Administration");

adminMenu.setActionCommand("Administration");

menuBar.add(adminMenu);

bulkLoadMenuItem.setText("Bulk Load");

bulkLoadMenuItem.setActionCommand("Bulk Load");

adminMenu.add(bulkLoadMenuItem);

drsMenuItem.setText("DRS override");

drsMenuItem.setActionCommand("DRS override");

adminMenu.add(drsMenuItem);

helpMenu.setText("Help");

helpMenu.setActionCommand("Help");

menuBar.add(helpMenu);

tutorialMenuItem.setText("Tutorial");

tutorialMenuItem.setActionCommand("Tutorial");

helpMenu.add(tutorialMenuItem);

bulkLoadFormatMenuItem.setText("Bulk Load Format");

bulkLoadFormatMenuItem.setActionCommand("Bulk Load Format");

helpMenu.add(bulkLoadFormatMenuItem);

aboutMenuItem.setText("About");

aboutMenuItem.setActionCommand("About");

helpMenu.add(aboutMenuItem);

//}}

JSplitPane2 = new javax.swing.JSplitPane();

upperPanel = new SeriesDescPanel();

JScrollPane2 = new javax.swing.JScrollPane(upperPanel,

ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

JScrollPane3 = new javax.swing.JScrollPane();

JSplitPane2.setOrientation(0);

JSplitPane2.setDividerSize(1);

JSplitPane2.setOneTouchExpandable(true);

JSplitPane1.setRightComponent(JSplitPane2);

JSplitPane1.setLeftComponent(viewPane);

viewPane.add(alphabeticPane);

viewPane.add(searchDataPane);

viewPane.setTitleAt(0,"All");

viewPane.setTitleAt(1,"search");

//JScrollPane1.setMinimumSize(new Dimension(126, 478));

JSplitPane2.setTopComponent(JScrollPane2);

//JScrollPane2.setMinimumSize(new Dimension(426, 409));

JSplitPane2.setBottomComponent(JScrollPane3);

lowerPanel = new SeriesDescMapPanel();

seriesTreeModel = new SeriesTreeModel(SeriesMaintenanceUI.getSeriesGroupInfo());

tickersTree.setModel(seriesTreeModel);

alphabeticPane.getViewport().setView(tickersTree);

//JScrollPane2.getViewport().setView(upperPanel);

//JScrollPane2.setViewportView(upperPanel);

//upperPanel.scrollRectToVisible(new Rectangle(upperPanel.getWidth(),

//upperPanel.getHeight(),1,1));

JScrollPane3.getViewport().setView(lowerPanel);

//JSplitPane2.setPreferredSize(new Dimension(426,200));

}

SeriesDescPanel upperPanel;

SeriesDescMapPanel lowerPanel;

SeriesTreeModel seriesTreeModel;

SeriesTreeModel searchTreeModel;

javax.swing.JSplitPane JSplitPane2;

javax.swing.JScrollPane JScrollPane2;

javax.swing.JScrollPane JScrollPane3;

javax.swing.JTree tickersTree= new javax.swing.JTree();

javax.swing.JTree searchTree= new javax.swing.JTree();

javax.swing.JScrollPane alphabeticPane = new javax.swing.JScrollPane();

javax.swing.JTabbedPane viewPane= new JTabbedPane(SwingConstants.BOTTOM);

javax.swing.JScrollPane searchDataPane = new javax.swing.JScrollPane();

//{{DECLARE_CONTROLS

javax.swing.JSplitPane JSplitPane1 = new javax.swing.JSplitPane();

javax.swing.JMenuBar menuBar = new javax.swing.JMenuBar();

javax.swing.JMenu seriesMenu = new javax.swing.JMenu();

javax.swing.JMenuItem newSeriesGroupMenuItem = new javax.swing.JMenuItem();

javax.swing.JMenuItem newSeriesMenuItem = new javax.swing.JMenuItem();

javax.swing.JSeparator JSeparator1 = new javax.swing.JSeparator();

javax.swing.JMenuItem serachMenuItem = new javax.swing.JMenuItem();

javax.swing.JSeparator JSeparator2 = new javax.swing.JSeparator();

javax.swing.JMenuItem saveMenuItem = new javax.swing.JMenuItem();

javax.swing.JSeparator JSeparator3 = new javax.swing.JSeparator();

javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();

javax.swing.JMenu adminMenu = new javax.swing.JMenu();

javax.swing.JMenuItem bulkLoadMenuItem = new javax.swing.JMenuItem();

javax.swing.JMenuItem drsMenuItem = new javax.swing.JMenuItem();

javax.swing.JMenu helpMenu = new javax.swing.JMenu();

javax.swing.JMenuItem tutorialMenuItem = new javax.swing.JMenuItem();

javax.swing.JMenuItem bulkLoadFormatMenuItem = new javax.swing.JMenuItem();

javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

//}}

Pl. help me in resolving this.

Ashok

ashok1000 at 2007-6-29 11:16:50 > top of Java-index,Archived Forums,Swing...
# 5

> The scroll bars are showing up but the

> components inside the Panel are not moving. I want

> the components to move when i am scrolling.

The JPanel will only the scroll ("components will only move") if the JPanel is not already entirely visible in the JScrollPane. You still have not yet said whether some components in the JPanel are visible while others are not.

To illustrate, the JPanel will only scroll in this situation (S=JScrollPane, P = JPanel, abcd = components in JPanel):

SSSSSSSSSSSSS

SPPPPPPPPPPPS

SPaPS

SPbPS

SSSSSSSSSSSSS

PcP

PdP

PPPPPPPPPPP

but not in this situation:

[code]

SSSSSSSSSSSSS

SPPPPPPPPPPPS

SPaPS

SPbPS

SPcPS

SPdPS

SPPPPPPPPPPPS

SSSSSSSSSSSSSS

earljavadev at 2007-6-29 11:16:50 > top of Java-index,Archived Forums,Swing...
# 6

I am sorry.Yes, only part of the JPanel is visible and the components in that part are only showing up.When i drag the split pane's border down then only i could see the total JPanel and all the components in it.My manager want it like, with out dragging the border itself the components should scroll just like the rows in a JTable scrolls . I am sending the JPanel subclass code.

public class SeriesDescMapPanel extends JPanel

{

public SeriesDescMapPanel()

throws RemoteException

{

// This code is automatically generated by Visual Cafe when you add

// components to the visual environment. It instantiates and initializes

// the components. To modify the code, only use code syntax that matches

// what Visual Cafe can generate, or Visual Cafe may be unable to back

// parse your Java file into its visual environment.

//{{INIT_CONTROLS

setLayout(null);

setSize(385,309);

dataFieldTypeLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

dataFieldTypeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

dataFieldTypeLabel.setText("Data Field Type");

add(dataFieldTypeLabel);

dataFieldTypeLabel.setBounds(12,13,112,16);

add(dataFieldTypeComboBox);

dataFieldTypeComboBox.setBounds(132,13,217,22);

dataSourceLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

dataSourceLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

dataSourceLabel.setText("Data Source");

add(dataSourceLabel);

dataSourceLabel.setBounds(24,42,98,17);

add(dataSourceComboBox);

dataSourceComboBox.setBounds(132,41,217,22);

sourceTimeZoneLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

sourceTimeZoneLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

sourceTimeZoneLabel.setText("Source Timezone");

add(sourceTimeZoneLabel);

sourceTimeZoneLabel.setBounds(12,68,108,18);

add(timezoneComboBox);

timezoneComboBox.setBounds(132,70,217,22);

hedgedCodeLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

hedgedCodeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

hedgedCodeLabel.setText("Hedged Code");

add(hedgedCodeLabel);

hedgedCodeLabel.setBounds(12,98,109,19);

add(hedgedCodeComboBox);

hedgedCodeComboBox.setBounds(132,98,217,21);

expressedCurrencyLabel.setText("Expressed Currency");

add(expressedCurrencyLabel);

expressedCurrencyLabel.setBounds(7,126,118,18);

add(expressedCurrencyComboBox);

expressedCurrencyComboBox.setBounds(132,127,217,22);

sourceDescriptionLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

sourceDescriptionLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

sourceDescriptionLabel.setText("Source Description");

add(sourceDescriptionLabel);

sourceDescriptionLabel.setBounds(3,158,119,17);

add(sourceDescriptionTextField);

sourceDescriptionTextField.setBounds(132,156,217,22);

sourceTickerLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

sourceTickerLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

sourceTickerLabel.setText("Source Ticker");

add(sourceTickerLabel);

sourceTickerLabel.setBounds(12,186,108,15);

add(sourceTickerTextField);

sourceTickerTextField.setBounds(132,184,217,22);

sourceFieldLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

sourceFieldLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

sourceFieldLabel.setText("Source Field");

add(sourceFieldLabel);

sourceFieldLabel.setBounds(12,214,107,21);

add(sourceFieldComboBox);

sourceFieldComboBox.setBounds(132,215,217,22);

add(seriesDataLabel);

seriesDataLabel.setBounds(84,276,240,12);

JCheckBox1.setText("Force full refresh of the series");

JCheckBox1.setActionCommand("Force full refresh of the series");

add(JCheckBox1);

JCheckBox1.setBounds(108,252,216,24);

//}}

}

//{{DECLARE_CONTROLS

javax.swing.JLabel dataFieldTypeLabel = new javax.swing.JLabel();

javax.swing.JComboBox dataFieldTypeComboBox = new javax.swing.JComboBox();

javax.swing.JLabel dataSourceLabel = new javax.swing.JLabel();

javax.swing.JComboBox dataSourceComboBox = new javax.swing.JComboBox();

javax.swing.JLabel sourceTimeZoneLabel = new javax.swing.JLabel();

javax.swing.JComboBox timezoneComboBox = new javax.swing.JComboBox();

javax.swing.JLabel hedgedCodeLabel = new javax.swing.JLabel();

javax.swing.JComboBox hedgedCodeComboBox = new javax.swing.JComboBox();

javax.swing.JLabel expressedCurrencyLabel = new javax.swing.JLabel();

javax.swing.JComboBox expressedCurrencyComboBox = new javax.swing.JComboBox();

javax.swing.JLabel sourceDescriptionLabel = new javax.swing.JLabel();

javax.swing.JTextField sourceDescriptionTextField = new javax.swing.JTextField();

javax.swing.JLabel sourceTickerLabel = new javax.swing.JLabel();

javax.swing.JTextField sourceTickerTextField = new javax.swing.JTextField();

javax.swing.JLabel sourceFieldLabel = new javax.swing.JLabel();

javax.swing.JComboBox sourceFieldComboBox = new javax.swing.JComboBox();

javax.swing.JLabel seriesDataLabel = new javax.swing.JLabel();

javax.swing.JCheckBox JCheckBox1 = new javax.swing.JCheckBox();

//}}

Pl. help me in resolving this.

Thanx

Ashok

ashok1000 at 2007-6-29 11:16:50 > top of Java-index,Archived Forums,Swing...