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.
thanks.
-David
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