Seeing what components 'fit' a frame does not make sense to me. From that decide on the layout manager to be used and then create the code. In a real application you would design the GUI using paper and pencil and then decide on how the components should be displayed when the frame size is changed. Then do the same for the other 2 textareas.Įither the components expand to fill the frame or the frame will have a lot of 'blank' space, the choice is yours. The scroll pane that contains the text area pays attention to these hints when determining how big the scroll pane should be. The two arguments to the JTextArea constructor are hints as to the number of rows and columns, respectively, that the text area should display. The solution is to use a different JTextArea constructor, so change line 30 to textArea = new JTextArea(5, 10) If I maximize the screen, there are very much blank spaces. If I put text into one of the JTextAreas, the scrollbar doesn't work tVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS) ScrollPane3 = new JScrollPane(textArea3) ScrollPane2 = new JScrollPane(textArea2) GridBagConstraints c = new GridBagConstraints() JScrollPane scrollPane, scrollPane2, scrollPane3 JTextArea textArea, textArea2, textArea3 The JPanel will now resize to fit the frame rather than the textarea.īTW you were creating 2 frames, 2 textareas and 2 scrollpanes which I have also corrected. Panel.add(scrollPane, BorderLayout.PAGE_START) int s (int) (d.getWidth() < d.getHeight() d.getHeight() : d. tLayout(new FlowLayout(FlowLayout.LEADING)) // sets s to the least of height and width. The trick is to use a JPanel as in intermediary between the textarea and the frame like this. The JTextArea will be resized to fill the JFrame even if you set the preferred and maximum size because you can't have 'empty space' in the JFrame when it bigger than the text area. What I want is to say that the JTextArea has to be 400px by 50px always, unregarded the size of the JFrame. If I'm running this code and maximize the JFrame, the JTextArea will become bigger (it fills the whole JFrame). My question is: How can I set the size of the JTextArea to a fixed value? When I run this code, Processing hides his own PApplet and creates a JFrame with a JTextArea in it. In your case, it returns a new instance of Dimension made of twice the same value: s, which is the biggest of the width and height you set via WindsetPreferredSize. tVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS) WindgetPreferredSize returns a Dimension instance that holds both the width and the height that your Wind instance wants to have. JScrollPane scrollPane = new JScrollPane() I am searching on the web for a long time to get a JTextArea in my Processing sketch.īecause it isn't possible to get Java Swing or Java AWT into a PApplet, I tried to create a code which creates a JFrame with a JTextArea in it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |