Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-18-2008, 09:18 PM
Member
 
Join Date: Jul 2008
Posts: 14
nidhirastogi is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 09-07-2008, 05:42 AM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 898
Fubarable is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 08: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 07:52 AM
code hint scroll bar ? tryit Eclipse 3 04-28-2008 09:07 AM
Scroll thumb on the ScrollPanel SteM AWT / Swing 3 12-05-2007 08:35 PM
Jtextarea and scroll ziniestro AWT / Swing 2 06-01-2007 05:59 PM


All times are GMT +3. The time now is 08:42 PM.


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