-
Adding Scrolling to JPanel
Hello All,
I have a form with a JPanel and a JScrollPane. The panel has a row of components like JTextField, Combo box, check box etc. A button will generate another row of the same components mentioned above. I would like to add scrolling to the JPanel as the number of rows increase so that I can scroll up and down. I am using JDeveloper and my problem is that the scrolling functionality is not added when the number of rows increase. Can any one help how to solve this problem. Any code snippets/explanation will be highly appreciated. I have to urgently implement it.
Thanks in advance.
Kind regards and best wishes.
Hasnain.
Here is my code sample.
// Declarations
private JButton jButton1 = new JButton();
private XYLayout xYLayout1 = new XYLayout();
private ScrollPane scrollPane1 = new ScrollPane();
private Panel panel1 = new Panel();
private JTextField jTextField2 = new JTextField();
// Initialization and setup
this.getContentPane().setLayout( null );
this.setSize(new Dimension(842, 586));
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(10, 260, 75, 25));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
scrollPane1.setBounds(new Rectangle(90, 65, 335, 170));
panel1.setLayout(null);
jTextField2.setBounds(new Rectangle(5, 5, 85, 20));
jTextField2.setText("First TextField");
panel1.add(jTextField2, null);
scrollPane1.add(panel1, null);
this.getContentPane().add(scrollPane1, null);
this.getContentPane().add(jButton1, null);
// action listener method for the button
int x = jTextField2.getBounds().x;
int y = jTextField2.getBounds().y;
JTextField f = new JTextField();
f.setText("Second TextField");
f.setBounds(x,y+20,jTextField2.getWidth(),jTextField2.getHeight());
panel1.add(f,null);
panel1.repaint();
jTextField2 = f;
Similar Threads
-
Replies: 6
Last Post: 01-07-2010, 11:36 PM
-
Replies: 2
Last Post: 06-01-2006, 10:00 AM
-
By homer2001 in forum Java
Replies: 0
Last Post: 03-12-2006, 08:30 PM
-
By Shiva Prasad in forum VB Classic
Replies: 4
Last Post: 08-06-2001, 03:42 AM
-
By Munchkin in forum Java
Replies: 3
Last Post: 03-16-2001, 04:58 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks