Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
just wondering, why my jcombo box at box 2 not shown up ?
im new in java

What I have tried:

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.*;

public class CronJob extends JFrame {

    CronJob(String title) {
        super(title);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//********** minute **********************************        
        Vector minute = new Vector();
        minute.add(0, "0");
        minute.add(1, "1");
        minute.add(2, "2");
        minute.add(3, "3");
        minute.add(4, "4");
        minute.add(5, "5");

//********** Hour **********************************  
        Vector hour = new Vector();
        hour.add(0, "0");
        hour.add(1, "1");
        hour.add(2, "2");
        hour.add(3, "3");
        hour.add(4, "4");
        hour.add(5, "5");

        
    
        JComboBox jcb = new JComboBox(minute);
        getContentPane().add(jcb);
        
        JComboBox jcb2 = new JComboBox(hour);
        getContentPane().add(jcb2);
        
        setSize(40, 60);
        setVisible(true);

    }

    //*********** minute****************
    public static void main(String[] args) {
        new CronJob("Cron Job");
    }

}
Posted
Updated 13-Nov-17 5:36am
Comments
Richard MacCutchan 13-Nov-17 3:42am    
I suspect there is some other method that you need to call to align the combo boxes properly in the frame. Check the swing documentation.

Try following code.

JComboBox jcb = new JComboBox(minute);
     //set size and position
     jcb.setSize(100, 20);
     jcb.setLocation(10, 10);

     JComboBox jcb2 = new JComboBox(hour);
     jcb2.setSize(100, 20);
     jcb2.setLocation(120, 10);

     getContentPane().add(jcb);
     getContentPane().add(jcb2);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900