Results 1 to 6 of 6

Thread: JViewport class of java

  1. #1
    Join Date
    Dec 2009
    Posts
    38

    JViewport class of java

    Hi All,

    I am totally confused with JViewport class of advanced java. I have knowledge about the 'SpinnerListModel class'. But 'SpinnerListModel' class is completely new for me. I know it very important class of the java programming. So please let know something about the 'SpinnerListModel class' with suitable example for it. Your help would be greatly appreciated over this issue.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: JViewport class of java

    Hi friend,

    Through JViewport class you see the underlying information.When you scroll, what moves is the viewport. In general this approach is much faster. Compared to the backing store approach this avoids the overhead of maintaining an offscreen buffer and having to do two copyAreas. Compared to the non backing store case this approach will greatly reduce the painted region.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: JViewport class of java

    I suggest you to go review following methods of JViewport class of java:
    1. paint(Graphics gp)
    2. remove(Component chld)
    3. isBackingStoreEnabled()
    4. repaint(long tm, int x1, int y1, int w1, int h1)
    5. scrollRectToVisible(Rectangle cntRect)
    6. setExtentSize(Dimension newExt)

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: JViewport class of java

    Hi, following is the example of 'JViewport class', please study it carefully:
    Code:
    class JViewport extends Container
    {
           public JViewport () {
        }
     public void setView(Component child2) {
    	if ((child2 instanceof Scrollable) == false &&
    	    (child2 instanceof TableHeader) == false) {
    	    throw new IllegalArgumentException(
    		"JViewport's view must be a Scrollable or a TableHeader");
    	}
    	if (child1 != null)
    	    super.remove(child1);  
    	super.add(child2);
    	child1 = child2;
        }
       public Component getView() {
    	return child1;
        }
        public void draw(Toolkit toolkit) {
    		Point origin = getLocationOnScreen();
    	toolkit.setClipRect(new Rectangle(origin, getExtentSize()));
    	child1.draw(toolkit);
    	toolkit.resetClipRect();
        }
            public Point getViewPosition() { return child1.getLocation(); }
           void setExtentSize(int width, int height) {
    	_extent = new Dimension(width, height);
        }
         public Dimension getExtentSize() {
    	return new Dimension(_extent);
        }
        public void debug(int level_) {
    	for (int i=0; i<level_; i++)
    	    System.err.print("    ");
    	System.err.println("Viewport origin=" + _origin + 
    	    " size=" + getSize() );
    	super.debug(level_ + 1);
        }
        private Component child1;
        private Dimension _extent;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: JViewport class of java

    A JViewport class of java comprises three nested class. First nested class is 'JComponent' which is inherited from 'JComponent.AccessibleJComponent'. The another nested class is 'Component'. This nested class is basically inherited from Component.FlipBufferStrategy and Component.AccessibleAWTComponent. The last and very important nested is named as 'Container', this nested class is inherited from 'Container.AccessibleAWTContainer'

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: JViewport class of java

    Hello friend,

    I know it is very complicated to use the JViewport class, but the following program shows the simplest way of using JViewport class:
    Code:
    import javax.swing.Jtable;
    import javax.swing.JViewport;
    
    public class JViewDemo {
    
      public static void main(final String args[]) {
        final Object rows[][] = { { "one", "1" }, { "two", "2" },
            { "three", "3" } };
        final Object headers[] = { "Italic", "Digit" };
        
        JframeJ frameJ = new JframeJ("Scrollless tableC");
        frameJ.setDefaultCloseOperation(JframeJ.EXIT_ON_CLOSE);
        
        JtableC tableC = new JtableC(rows,headers);
        
        JScrollPane scrollPane = new JScrollPane(tableC);
        JViewport viewport = new JViewport();
        viewport.setView(tableC);
        scrollPane.setColumnHeaderView( new JLabel("table header here"));
        scrollPane.setRowHeaderView(viewport);
        
        frameJ.add(scrollPane, BorderLayout.CENTER);
        frameJ.setSize(500, 150);
        frameJ.setVisible(true);
      }
    }

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. JDesktopPane class of java
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 08:14 AM
  3. What is TransferSupport Class in Java?
    By DANIEL 602 in forum Software Development
    Replies: 4
    Last Post: 13-02-2010, 06:54 AM
  4. Use of JWindow class in java
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 11:11 AM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,456,256.22726 seconds with 17 queries