Results 1 to 2 of 2
  1. #1
    vivekkumar is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default Getting and Displaying Swing Components From DataBase

    hi,

    I,m storing Swing Components in Database and i want the components like TextField and ComboBox to be created and Displayed while retrieving from database.
    for example, 10 JLabels in one column along with that 10 (8 Textfields + 2 ComboBox) components in another Column. While retrieving im able to print 10 labels and 10 textfields in proper alignment.
    like Label1 TextField1
    Label2 TextFiled2
    Label3 TextField3
    ------------------
    ------------------
    What im doing is Im getting JLabels in an one array and JTextField in another array with help of for loop im displaying the Label ,TextField in the Panel. this is my coding
    count is integer variable that having the total number of labels in the database.
    ---------------------------------------------------------------------------------------
    JLabel[] label=new JLabel[count];
    JTextField text[];
    int k=60;
    for(int i=0;i<label.length;i++)
    {
    text[i]=new JTextField();
    text[i].setText("abcd");
    text[i].setFont(textFieldFont);
    text[i].setBounds(200, k, 100, 25);

    k+=30;
    }
    -------------------------------------------------------------------

    How could i create the JTextField , JComboBox simultaneously.
    i had tried , ResultSet rs =Stmt.executeQuery("select component from
    dg_components");

    JComponent comp[]=new Jcomponent[count];
    for(int i=0;i<label.length,i++)
    {
    if(rs.getString(1).equals("JTextField"))
    {
    comp[i]=
    (JTextField)Class.forName("javax.swing.JTextField" ).getConstructor(new
    Class[]{String.class}).newInstance(new Object[]{" "});

    comp[i].setFont(textFieldFont);
    comp[i].setBounds(200, k, 100, 25);
    } else if(rs.getString(1).equals("JComboBox"))
    {
    comp[i]=
    (JComboBox)Class.forName("javax.swing.JComboBox"). getConstructor(new
    Class[]{String.class}).newInstance(new Object[]{" "});

    // HERE IM NOT ABLE TO SET THE MODEL FOR THE JCOMBO BOX , BCZ IT
    IS JCOMPONENT ..
    }
    }

    CAN ANYONE TELL SOME OTHER WAY TO DO THIS......

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Any reason why you are storing the components in the database as opposed to the values of the components? you can add items to a JComboBox by calling the addItem function.

Similar Threads

  1. add remove swing components
    By willemjav in forum New To Java
    Replies: 6
    Last Post: 10-09-2008, 07:37 PM
  2. Displaying Chinese characters on Swing components
    By vaskarbasak in forum AWT / Swing
    Replies: 3
    Last Post: 06-26-2008, 08:27 AM
  3. Swing Components Placing
    By ne2000 in forum Eclipse
    Replies: 2
    Last Post: 06-23-2008, 08:00 AM
  4. How to print Swing components
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. HTML on Swing Components
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-27-2007, 09:51 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
  •