Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

scrolling feature in a frame

  Asked By: Don    Date: Jan 11    Category: Java    Views: 966
  

Can anyone send me a sample code of having scrolling feature in a
frame, i am either getting scrolling feature using scollpane or able
to add components. can anyone please tell me who i can have
scrolling feature & also add components.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Dep Tran     Answered On: Jan 11

Have you checked Java Online Source for the sample
source code? I do not have source code  available, but
according to the way I interpreted your question is
create a Frame, add scrolling  pane feature, and then
some other components.

////////////
// creat a frame  named Scroll Bar Demo
public class ScrollDemo extends JFrame {
public ScrollDemo() {
super("Scroll Bar Demo");
setSize(300,250);
CustomScrollPane sp=new CustomScrollPane(new
JLabel());
getContentPane().add(sp); // add  Scrollpane to
Frame
// add other components  if you wanted to

WindowListener wndCloser=new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser); // register window
listener
setVisible(true); // without this you can not see
the frame
}

// execute application
public static void main(String[] args) {
new ScrollDemo(); // create a new application
}
}
}

 
Answer #2    Answered By: Archana Kamble     Answered On: Sep 05

You can run the following code.It works in java 7


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.basic;

import javax.swing.*;
/**
*
* @author mac
*/
public class ScrollDemo extends JFrame {

public ScrollDemo() {

JTextArea txtArea = new JTextArea(20,20);
txtArea.setAutoscrolls(true);
txtArea.setEditable(true);
JPanel panel= new JPanel();
panel.add(txtArea);
JScrollPane scrollPane = new JScrollPane(panel);

// scrollPane.setVerticalScrollBar(JScrollBar.VERTICAL);

setContentPane(scrollPane);
setTitle("scrollpane demo");
setSize(300,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new ScrollDemo();
}

}

 
Didn't find what you were looking for? Find more on scrolling feature in a frame Or get search suggestion and latest updates.




Tagged: