Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scroll pane not appearing 1

Status
Not open for further replies.

briggsy79

Programmer
Feb 23, 2001
68
SE
Hi all,
I'm trying to make an app that shows a label inside a scroll pane. For some reason it doesnt work.
And I really dont have a clue why...im sure its simple.

Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class MainFrame extends JFrame {


  BorderLayout borderLayout1 = new BorderLayout();
  CardLayout cardLayout1 = new CardLayout();
  GridLayout gridLayout1 = new GridLayout();

  private JPanel panelOne = new JPanel();
  private JPanel panelCard = new JPanel();
  private JScrollPane panelScroll = new JScrollPane();
  private JPanel panelGrid = new JPanel();
  private Container contentPane;

  //Construct the frame
  public MainFrame() {
    JLabel room = new JLabel("Room is a short word, but with the addition of a whole lot of meaningless crap it can be made so much better just like this");

    contentPane = this.getContentPane();
    contentPane.setLayout(borderLayout1);

    panelOne.setLayout(borderLayout1);
    //panelCard.setLayout(cardLayout1);
    gridLayout1.setColumns(2);
    gridLayout1.setRows(2); 


    panelGrid.setLayout(gridLayout1);
    panelGrid.add(room);
    panelScroll.getViewport().add(panelGrid, null);
    panelCard.add(panelScroll);
    panelOne.add(panelCard);
    panelScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    panelScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    contentPane.add(panelOne, BorderLayout.CENTER);

  }
  public static void main(String [] args)
  {
	  MainFrame mf = new MainFrame();
	  mf.setVisible(true);
  }

}

thanks.

-David
 
Try this:-
Code:
  public MainFrame() {
    setSize(500,400);
    JLabel room = new JLabel("Room is a short word, but with the addition of a whole lot of meaningless crap it can be made so much better just like this");

    contentPane = this.getContentPane();
    contentPane.setLayout(borderLayout1);

    panelOne.setLayout(borderLayout1);
    panelCard.setLayout(cardLayout1);
    gridLayout1.setColumns(2);
    gridLayout1.setRows(2); 

    panelGrid.setLayout(gridLayout1);
    panelGrid.add(room);
    panelScroll.getViewport().add(panelGrid, null);
    panelCard.add(panelScroll, "Card1");
    panelScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    panelScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    contentPane.add(panelCard, BorderLayout.CENTER);

  }

I took out panelOne which is a redundant panel and re-instated the layout manager on panelCard. Oh, and I also put in a setSize for the Frame.

Tim
 
thanks so much
that was obviously just an app to show my problem, I fixed up my main app and it worked first time. Always good.

-David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top