-
JScrollPane H E L P
Hello All.
I have created a JInternalFrame inside a JDesktopPane. There is a scrollPane inside of the JInternalFrame. Inside this scollPane is a list of items. I need to find out what section of this list is currently being shown to the user while they are scolling up and down.
For example there is a list of 20 items in my internal frame .. but the InternalFrame has been expanded / minimized to only show 5 of them. How do I know the coords that the viewport is in compairison to the original list.
I have NO idea where to even start trying to figure this out. Any suggestions would be very much appreciated!
-
I'm learning that type UI thing to.
It could be using an array and not a List DataModel().
Take a look in the Docs for the
instance declaration of the class type.
Either JList or JScrollPane contains a boolean method for
retrieving whether a list
element is in the visible bounds as also one the two of contains
a retrieval allowing a pair of indexes to be returned much similar to java.awt.Dimension() for the
topmost and bottom-most visibles.
It is appearing to me that it requires to use the sun approved method of declaring a
DataModel() and ListModel() for the list to operate correctly.
Various abstract classes could be
assosciated and are when retrieving or modifying a UI components position or size.
For size and position Container
and Component classes need to
be cast into from the pre-declared original e.g.
re-referenced from a Jscrollpane and cast to a
JComponent (abstract class).
More complicated though is using java.awt.rectangle and
util with a class called GraphicsConfiguration with
virtual device array references.
Hope that helped.
-
Originally posted by nicephotog
Hope that helped.
was that English?
im a fairly smart guy, and i didnt have a clue what that was all about.. dont they put full stop keys [ . ] on keyboards in australia? i heard things down there can be pretty expensive, maybe not putting the odd key or two on a keyboard, is the economic solution...
as for the OP.. man, you need to read the API documentation more..
JScrollPane has a method getViewPort(), that gets you the JViewPort.. and when we look at the methods of that.. we see getViewRect() which returns you the visible rectangle, stemming from the coordinates in the top left, of what the viewport is currently looking at
suppose your viewport is 100x100 pixels, and youre dead in the centre of a 300x300 sized thing.. calling getViewPort().getViewRect() will return you the coordinates 100,100,200,200
because the top left of your viewport is looking at pixel 100,100 and the bottom right is looking at 200,200
-
Jscrollpane clearer ideas
read this and see the examples at this URL
http://java.sun.com/docs/books/tutor...ents/list.html
suppose....
int nowTopis=0; //declared and ready
int nowBaseis=0; //declared and ready
listModel = new DefaultListModel();
// add the cells values to the list
listModel.addElement("each value here");
//now put the lists cells into the list
JList spanner=new JList(listModel);
nowTopis=spanner.getFirstVisibleIndex();
nowBaseis=spanner.getLastVisibleIndex();
//note you can use a JPanel to add
//to the JScrollPane() as the viewport
//but cast to a JComponent to
//control the size and to have a reference
//for resizing e.g. use the JComponent
//reference to do sizing and to change
//the JList use the JPanel reference
//Truthfully though
//"just change the list model" not the
//JPanel contents.
//JList provides
//setVisibleRowCount(int visibleRowCount)
//assosciated also and useable for that
//you appear to be needing for coords is
//javax.swing Interface ListCellRenderer
//JComponent setMaximumSize(Dimension maximumSize)
e.g. suppose...
JPanel contentment=new JPanel();
contentment.add(spanner);
//This is the cast syntax below because
//Component and Container are abstract
//classes and cannot be instantiated by
//"new" but are not static((static)declared
//first not used instantly)
// Very imortant next line(cast to)
JComponent sqishhh=(JComponent)contentment;
sqishhh.setMaximumSize(new Dimension(200,500));
sqishhh.setMinimumSize(new Dimension(100,300));
sqishhh.setVisible(true);
JScrollPane yawn=new JScrollPane(sqishhh);
// do setting (note Viewport and Scrollable
//interface).
JComponent scrunch=(JComponent)yawn;
// and add requirements...
//enough dot operation of this struct
//i hope.
stop...
-
Thanks all, appreciate the time that you took do to the post! After reading the posts (And going back to look at the API) the program is running perfectly. Thanks again.
Have a great day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks