0

I need help adding a scrollbar to an empty textbox that will output the information that i input into the required textboxes by then clicking the buttons. My issue is im not sure how to implement the scrollbar correctly with the textbox that is in the code, it just goes over and it and does nothing like in the picture shown. I need it to align with the textbox and not mess with the Jtextfield so that it can properly scroll the textbox, i will handle the events after i finish the design.

Code:

    // Display box for all the inputs
    JTextField outputBox = new JTextField(5);
    wv.add(outputBox, 39, 575, 800, 150);
    JScrollBar outputBoxScrollBar = new JScrollBar(JScrollBar.VERTICAL, 30, 20, 0, 500);
    wv.add(outputBoxScrollBar, 790, 300, 50 , 250);

Output:

GUI Picture with the scrollbar and Jtextfield box

https://i.stack.imgur.com/oHnY8.png - Link for different OS

  • 2
    1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 3) Provide ASCII art or a simple drawing of the *intended* layout of the GUI at minimum size, .. – Andrew Thompson Apr 20 '20 at 07:19
  • 1
    .. and if resizable, with more width and height - to show how the extra space should be used. – Andrew Thompson Apr 20 '20 at 07:23

1 Answers1

0
  1. A JTextField is single-line, I guess you are looking for JTextArea.
  2. You need to wrap JTextArea in a JScrollPane (not a JScrollBar) like this.
        JTextArea outputBox = new JTextArea(5, 20); //rows, columns
        wv.add(new JScrollPane(outputBox), 790, 300, 50 , 250);
Horse Badorties
  • 308
  • 2
  • 10