Home > Back-end >  The JScrollPane scroll bar is not effective
The JScrollPane scroll bar is not effective

Time:11-01

JLabel jll1=new JLabel (" round 1: ");
Jll1. SetBounds (0, 0, 40, 20).
Jll1. SetForeground (Color. White);

JTextField jt1=new JTextField ();
Jt1. SetBounds (45, 2, 200, 20).
Jt1. SetBorder (BorderFactory. CreateLineBorder (new Color (221, 160, 221)));
Jt1. SetBackground (new Color (221, 160, 221));
Jt1. AddKeyListener (this);

Jp1=new JPanel ();
//not set layout
Jp1. SetLayout (null);
Jp1. SetBounds (0, 0, 240, 500);
//jp1. SetPreferredSize (new Dimension (240, 500));
Jp1. SetOpaque (false);
Jp1. SetBorder (null);
Jp1. Add (jll1);
Jp1. Add (jt1);

JSP=new JScrollPane (jp1, ScrollPaneConstants VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants. HORIZONTAL_SCROLLBAR_ALWAYS);
JSP. SetHorizontalScrollBarPolicy (
The JScrollPane. HORIZONTAL_SCROLLBAR_AS_NEEDED);
JSP. SetVerticalScrollBarPolicy (
The JScrollPane. VERTICAL_SCROLLBAR_AS_NEEDED);
JSP. SetBounds (150, 60, 240, 120);
JSP. SetOpaque (false);
JSP. GetViewport (.) setOpaque (false);
JSP. SetBorder (null);
//JSP. SetViewportView (jp1);
//JSP. The add (jp1);
BGP. Add (JSP);
Public void keyTyped KeyEvent (e) {

RemoveKeyListener (this);
JLabel jlb1=new JLabel (" first "+ lunNum +" round: ");
Jlb1. SetBounds (0, 2 + 30 * (lunNum - 1), 40, 15);
Jlb1. SetForeground (Color. White);
Jp1. Add (jlb1);

JTextField jt2=new JTextField ();
Jt2. SetBounds (45, 30 * (lunNum - 1), 200, 20).
Jt2. SetBackground (new Color (221, 160, 221));
Jt2. SetBorder (BorderFactory. CreateLineBorder (new Color (221, 160, 221)));
Jt2. AddKeyListener (this);
Jp1. Add (jt2);
LunNum++;


//dynamically add components and refresh interface
BGP. UpdateUI ()
  • Related