-
JScrollPane with JTextArea
Hi,
I was wondering if anyone has a simple code of how to use JTextArea with JScrollPane? my results are displayed without any problem if the JScrollPane is not used.The code fetches the data from database and then displays it. This is a part of my code with JScrollPane in it..
public class Applet1 extends JApplet {
private JButton DbConnect = new JButton();
private JTextArea empValues = new JTextArea();
JScrollPane ScrollempValues=new JScrollPane(empValues);
//empvalues.setContentPane(ScrollempValues);
private Connection con;
private JLabel jLabel1 = new JLabel();
//ScrollempValues.getHorizontalScrollBar();
public Applet1() {
}
public void init() {
try {
jbInit();
} catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
this.getContentPane().setLayout(null);
DbConnect.setText("Click to Connect to DB");
DbConnect.setBounds(new Rectangle(90, 550, 175, 40));
DbConnect.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
connectToDB(e);
}
});
empValues.setBounds(new Rectangle(40, 50, 500, 500));
jLabel1.setText("Emp Records :");
jLabel1.setBounds(new Rectangle(45, 20, 155, 20));
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(empValues, null);
// getContentPane().add(ScrollempValues, BorderLayout.CENTER);
JScrollPane ScrollempValues = new JScrollPane( empValues );
this.getContentPane().add(ScrollempValues, BorderLayout.CENTER);
this.getContentPane().add(DbConnect, null);
Thanks,
nits.
-
Use this code for putting anything (like a JTextArea) into a JScrollPane:
theScrollPane.getViewport().add(theTextArea);
and all will be fine. You may want to alter some textarea linewrapping/wordwrapping too.
eschew obfuscation
Similar Threads
-
Replies: 3
Last Post: 10-11-2005, 04:28 AM
-
By rechmbrs in forum Java
Replies: 0
Last Post: 07-11-2005, 09:41 PM
-
Replies: 1
Last Post: 04-08-2005, 10:36 AM
-
By bilinmiyo in forum Java
Replies: 1
Last Post: 03-04-2005, 07:57 AM
-
By Huiyuanm in forum Java
Replies: 1
Last Post: 03-22-2000, 09:03 AM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|