Results 1 to 2 of 2
Thread: scroll a Jpanel in a JFrame
- 08-18-2008, 07:18 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 16
- Rep Power
- 0
scroll a Jpanel in a JFrame
Hi All
I need to make a JPanel inside a JFrame Scrollable. I have implemented a hexagonal grid in the Jframe and need to scroll it horizontally n vertically.
Plz. help.
My JPanel Code is :
public class DisplayPanel extends JPanel
{
private static final long serialVersionUID = 1L;
private int xMax=1000, yMax=1000;
// public Point2D listAP;
// DistancefromMN distMN = new DistancefromMN();
JLabel label;
class MyAdjustmentListener implements AdjustmentListener
{
public void adjustmentValueChanged(AdjustmentEvent e) {
repaint();
}
}
public DisplayPanel(int xMax,int yMax)
{
super(true);
this.xMax=xMax;
this.yMax=yMax;
setLayout(new BorderLayout());
setLayout(new BorderLayout());
JScrollBar hbar = new JScrollBar(
JScrollBar.HORIZONTAL, 30, 20, 0, 300);
JScrollBar vbar = new JScrollBar(
JScrollBar.VERTICAL, 30, 40, 0, 300);
hbar.setUnitIncrement(2);
hbar.setBlockIncrement(1);
hbar.addAdjustmentListener(new MyAdjustmentListener());
vbar.addAdjustmentListener(new MyAdjustmentListener());
add(hbar, BorderLayout.SOUTH);
add(vbar, BorderLayout.EAST);
}
}
and JFrame:
public class DisplayFrame extends JFrame
{
private static final long serialVersionUID = 1L;
private int maxX,maxY;
public DisplayFrame()
{
setLayout(new BorderLayout());
setTitle("Wireless Environment");
setSize(1290, 1290);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Toolkit toolkit = getToolkit();
// JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
// JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
// vbar.addAdjustmentListener(new MyAdjustmentListener());
// add(hbar, BorderLayout.SOUTH);
// add(vbar, BorderLayout.EAST);
DisplayPanel p=new DisplayPanel(maxX,maxY);
this.getContentPane().add(p);
this.validate();
setVisible(true);
}
class MyAdjustmentListener implements AdjustmentListener
{
public void adjustmentValueChanged(AdjustmentEvent e) {
//label.setText(" New Value is " + e.getValue() + " ");
repaint();
}
}
public static void main(String args[])
{
new DisplayFrame();
}
}
-
Similar Threads
-
Adding Multiple Panels and Single Scroll bar on the JFrame
By SANDY_INDIA in forum AWT / SwingReplies: 6Last Post: 07-28-2008, 06:04 PM -
Controlling Page Scroll Position in Jsp....f there are fewer than 4 pages only that n
By 82rathi.angara in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 07-05-2008, 02:11 PM -
code hint scroll bar ?
By tryit in forum EclipseReplies: 3Last Post: 04-28-2008, 07:07 AM -
Scroll thumb on the ScrollPanel
By SteM in forum AWT / SwingReplies: 3Last Post: 12-05-2007, 06:35 PM -
Jtextarea and scroll
By ziniestro in forum AWT / SwingReplies: 2Last Post: 06-01-2007, 03:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks