I want to create two non-editable textboxes (each will contain only one line) with a fixed size, but I want them to be scrollable (horizontally only) because I know the text they will contain will be very long. I want them to be below the two buttons I define below, and I want each textbox on their own row.
Problem is, everything shows up and buttons work as expected, but the textbox won't scroll, although I can somehow drag and select the rest of the text in the box that isn't visible. I don't know if labels are scrollable, would they be a better option?
Code:
public static void main(String[] args)
{
JFrame win = new JFrame("Window");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setSize(400, 300);
GridBagConstraints c = new GridBagConstraints();
win.setLayout( new GridBagLayout() );
JTextArea master = new JTextArea(1,1);
JTextArea vendor = new JTextArea(1,1);
master.setEditable(false);
vendor.setEditable(false);
master.setPreferredSize( new Dimension(100,20) );
vendor.setPreferredSize( new Dimension(100,20) );
master.setText(/*some really long string*/);
vendor.setText(/*some really long string*/);
JScrollPane mPane = new JScrollPane(master, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JScrollPane vPane = new JScrollPane(vendor, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
mPane.getHorizontalScrollBar().isVisible();
vPane.getHorizontalScrollBar().isVisible();
JButton one = new JButton("Select");
ActionListener select = new SelectButton(master, vendor);
one.addActionListener(select);
JButton two = new JButton("Run");
c.gridx = 0;
c.gridy = 0;
win.add(one, c);
c.gridx = 1;
c.gridy = 0;
win.add(two, c);
c.gridx = 0;
c.gridy = 1;
win.add(master, c);
win.add(mPane, c);
c.gridx = 0;
c.gridy = 2;
win.add(vendor, c);
win.add(vPane, c);
win.setLocationRelativeTo(null);
win.setVisible(true);
return;
}