Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-18-2008, 07:18 PM
Member
 
Join Date: Jul 2008
Posts: 14
Rep Power: 0
nidhirastogi is on a distinguished road
Default 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();

}
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-07-2008, 03:42 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,195
Rep Power: 5
Fubarable is on a distinguished road
Default
I think that you posted this in the wrong forum, that you wanted to post this in the Swing forum. Oh well, it's close anyway. Question though: why not just use a JScrollPane? That should make this whole thing easy.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-02-2009, 09:05 PM
Member
 
Join Date: Feb 2009
Location: USA
Posts: 1
Rep Power: 0
Dyhorbhox is on a distinguished road
Send a message via ICQ to Dyhorbhox
Default We are already a billion!
We are already a billion!

The number of the Internet users overcomed psychologicly important limit - a billion! This information can be found in the report of U.N.O., named "About informational economy". Amasing grow of the Internet continues, its number of users grew to 20%. First place is occupied by USA (200 million users), China (111 million users), Japan (85 million users).
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Multiple Panels and Single Scroll bar on the JFrame SANDY_INDIA AWT / Swing 6 07-28-2008 06:04 PM
Controlling Page Scroll Position in Jsp....f there are fewer than 4 pages only that n 82rathi.angara JavaServer Pages (JSP) and JSTL 1 07-19-2008 05:52 AM
code hint scroll bar ? tryit Eclipse 3 04-28-2008 07:07 AM
Scroll thumb on the ScrollPanel SteM AWT / Swing 3 12-05-2007 06:35 PM
Jtextarea and scroll ziniestro AWT / Swing 2 06-01-2007 03:59 PM


All times are GMT +2. The time now is 12:37 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org