Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    883

    A cosa serve la classe JViewPort in java

    L'unica cosa che ho trovato su JViewPort è questa frase

    The JViewport provides a window, or "viewport" onto a data source -- for example, a text file. That data source is the "scrollable client" (aka data model) displayed by the JViewport view. A JScrollPane basically consists of JScrollBars, a JViewport, and the wiring between them, as shown in the diagram at right.


    A common operation to want to do is to set the background color that will be used if the main viewport view is smaller than the viewport, or is not opaque. This can be accomplished by setting the background color of the viewport, via scrollPane.getViewport().setBackground(). The reason for setting the color of the viewport and not the scrollpane is that by default JViewport is opaque which, among other things, means it will completely fill in its background using its background color. Therefore when JScrollPane draws its background the viewport will usually draw over it.

    Non capisco che differenza ci sia tra scrivere questo codice

    JScrollPane editorScroll = new JScrollPane();
    JViewport port = editorScroll.getViewport();
    port.add(editor);

    ed il codice
    JScrollPane editorScroll = new JScrollPane(editor);

    a cosa mi serve il JViewport?

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    1,798
    Dipende da cosa devi fare.
    Mettiamo caso che tu voglia cambiare il componente da inserire nel JScrollPane.

    Nel primo caso rimane invariata l'istanza del JScrollPane e del JViewport, permettendoti in aggiungere un nuovo Component.

    Nel secondo crei una nuova istanza della class JScrollPane.

    Bisogna vedere anche il contesto in cui inserire il codice, cosiì isolato non è molto utile.

    Ovviamente IMHO.

    Ciao.
    Slack? Smack!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.