この記事では、主に、次のように、スイングコンポーネントのjscrollpaneスクロールバーの実装コードの例を研究しています。
/** scrollbar*/import javax.swing。*; public class demo1 extends jframe {jtextarea jta = null; jscrollpane jsp = null; public static void main(string [] args){// todo auto-generated method stub demo1 d = new demo1();} public demo1() jtextarea();/ * * jscrollpane(コンポーネントビュー、int vsbpolicy、int hsbpolicy) * jtaビューポートにビューコンポーネントを表示するjscrollpaneを作成し、ビューの位置は一対のスクロールバーによって制御されます。 * VSBPolicy垂直スクロールバーの表示ポリシー。デフォルトはscrollpaneconstants.vertical_scrollbar_as_neededです。 * HSBPolicyは、水平スクロールバーのディスプレイポリシーです。デフォルトはscrollpaneconstants.horizontal_scrollbar_as_neededです。 * If the horizontal scroll bar is not displayed, use JScrollPane.HORIZONTAL_SCROLLBAR_NEVER * If the vertical scroll bar is not displayed, use JScrollPane.VERTICAL_SCROLLBAR_NEVER * * If you want to display scroll bars in both directions in the end, you cannot do this directly * jsp = new JScrollPane(jta); *ディスプレイ効果は同じです * *スクロールバーは必要に応じて表示され、不要なときに表示されません */jsp = new jscrollpane(jta、jscrollbar_as_as_as_needed、jscrollpane.horizontal_scrollbar_as_ased); this.add(jsp); this.settitle( "notepad"); this.setsize(800、600); // [設定]ウィンドウを中心にこれを表示します。SetlocationRelativeto(null); this.setDefaultCloseoperation(jframe.exit_on_close); //ユーザーがフォームサイズのsetressableの変更を禁止する(false); this.setVisible(true);}} /*** Java SwingのJScrollpaneパネル*インターフェイスをセットアップすると、小さなコンテナ形式に表示されるコンテンツの大部分に遭遇する可能性があります。 * jscrollpaneパネルを使用できます。 JScrollpaneパネルは、Scrollbarsを備えたパネルであり、コンテナでもありますが、単一の *コントロールを配置するためによく使用され、レイアウトマネージャーを使用できません。 JScrollpaneパネルに複数のコントロールを配置する必要がある場合は、複数のコントロールをJPanelパネルに配置し、JScrollpaneコントロールにjPanelパネル全体を追加する必要があります。 * * @author gao */package com.gao; import java.awt.borderlayout; import javax.swing.jframe; import javax.swing.jpanel; Import javax.swing.jscrollpane; Import javax.swing.swing.jscrollpane; jframe {private jpanel contentspane; private jscrollpane scrollpane; private jtextarea textarea; public jscrollpanedemo(){contentspane = new jpanel(); contentspane.setborder(new emptyborder(5,5,5,5)); borderlayout(0,0)); this.setContentPane(contentSpane); scrollpane = new jscrollpane(); contentpane.add(scrollpane、borderlayout.center); textarea = new jtextarea(); // scrollpane.add(textarea); scrollpane.setviewportview(textarea); this.settitle( "スクロールパネル使用"); this.setDefaultCloseoperation(jframe.exit_on_close); this.setbounds(100、100、250、200); this.setVisible(true);} public static void main(string [] args){jscrollpanedemo example = new jscrollpanedemo();}}}効果:
上記は、スイングコンポーネントJScrollpane Scrollbarインスタンスコードに関するこの記事の全体的な内容です。私はそれが誰にでも役立つことを願っています。興味のある友人は、このサイトの他の関連トピックを引き続き参照できます。欠点がある場合は、それを指摘するためにメッセージを残してください。このサイトへのご支援をありがとうございました!