java - How to set JPanel fixed size such that the JScrollPane (scrolling) appears? -


I am working on a bit code with jfram with specific dimensions containing jpnl < / Code>. Here is my code:

  import javax.swing *; Import java.awt. *; The public square is spread across the ScrollPane JFrame {public ScrollPane ({{super ("title"); Set layout (new border layout ()); SetSize (320,240); JScrollPane scroller = new JScrollPane (new drawingpan); Scroller.setPreferredSize (new dimension (320,240)); (Scroller); SetDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); SetVisible (true); } Private Class DrawingPane JPanel {public DrawingPane () {super (); SetSize (640,480); Set minimum size (new dimensions (320,240)); }} Public static zero main (string [] args) {new scrollpane (); }}  

Even with the minimum size set for JPanel , scrolls do not appear

< Div class = "post-text" itemprop = "text">

All components are responsible for determining the preferred size, so layout managers can work properly. When doing custom painting, you must override the getPreferredSize () of your custom component to return the dimension of your component.

Read the section from the swing tutorial for more information. Working Examples


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -