combobox updation

combobox updation

View Answers

September 11, 2008 at 1:08 PM

Hi

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.text.SimpleDateFormat;

public class ComboBoxList extends JPanel implements ActionListener {
static JFrame frame;
JLabel result;
String currentdate;
String list;

public ComboBoxList() {
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
String[] patternExamples = {
"dd MMMMM yyyy",
"dd.MM.yy",
"MM/dd/yy",
"yyyy.MM.dd G 'at' hh:mm:ss z",
"EEE, MMM d, ''yy",
"h:mm a",
"H:mm:ss:SSS",
"K:mm a,z",
"yyyy.MMMMM.dd GGG hh:mm aaa"
};

currentdate = patternExamples[0];

JLabel lable1 = new JLabel("Enter the pattern string or");
JLabel lable2 = new JLabel("select one from the list:");

JComboBox patternList = new JComboBox(patternExamples);
patternList.setEditable(true);
patternList.addActionListener(this);

//Create the UI for displaying result.
JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING);
result = new JLabel(" ");
result.setForeground(Color.black);
result.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.black),
BorderFactory.createEmptyBorder(5,5,5,5)
));

//Lay out everything.
JPanel jpanel = new JPanel();
jpanel.setLayout(new BoxLayout(jpanel, BoxLayout.PAGE_AXIS));
jpanel.add(lable1);
jpanel.add(lable2);
patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
jpanel.add(patternList);

JPanel resultPanel = new JPanel(new GridLayout(0, 1));
resultPanel.add(resultLabel);
resultPanel.add(result);

jpanel.setAlignmentX(Component.LEFT_ALIGNMENT);
resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

add(jpanel);
add(Box.createRigidArea(new Dimension(0, 10)));
add(resultPanel);

setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

reformat();
} //constructor

public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String newSelection = (String)cb.getSelectedItem();
currentdate = newSelection;
reformat();
}

// date format taday
public void reformat() {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(currentdate);
try {
String dateString = formatter.format(date);
result.setForeground(Color.black);
result.setText(dateString);
}
catch (IllegalArgumentException e) {
result.setForeground(Color.red);
result.setText("Error: " + e.getMessage());
}
}

private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ComboBoxList example using in swing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
JComponent newContentPane = new ComboBoxList();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.setSize(300 ,200);
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

----------------------------------------
Please visit for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.

Amardeep

September 11, 2008 at 2:13 PM

thanks Amardeep,the code u gave is working fine...but i am using ItemListener inside an ActionListener of the menu...plz help









Related Tutorials/Questions & Answers:
combobox updation - Java Beginners
combobox updation  hi, i am using java swing to develop a gui.... It is required that on clicking a specific menu-the first combobox is populated using a vector, and then on clicking on a specific combobox item, the 2nd and 3rd
Updation and deletion - JSP-Servlet
Updation and deletion   How to provide updation and deletion in data view of jsp  Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets
Advertisements
updation of data in mysql
updation of data in mysql  http://www.roseindia.net/answers/viewqa/PHP/20822-Edit-the-record-.html sir , i want the above code as retreive of data from mysql ,but based on subject code(varchar) instead of id and my table format
comboBox validation
comboBox validation  dear sir. i want to know . how to validate radio button in struts using xml validation. thanks
to jsp combobox exmple
to jsp combobox exmple  to jsp combobox exmple
Flex Combobox
Flex Combobox  flex combobox with database as dataprovider   You can visit the following link for detailed tutorial on the topic. May this will be helpful to you. http://www.roseindia.net/flex/flex-combo-box.shtml
Combobox application - Swing AWT
Combobox application  hi, i am facing a problem in updation of the comboboxes i m using in an application...for the first time the selectec item does is not returned and thus i am unable to pass it as an argument to another
automatic updation of a form - JSP-Servlet
automatic updation of a form   Sir, I need the code for if we fill the details in one page(form) that details should be updated automatically in another table like page.Please provide the code for this problem in JSP or java
Flex Combobox
Flex Combobox  flex combobox with database as dataprovider  ... backgroundColor = '#CCCCFC' width = '100%' height = '100%'> <mx:ComboBox...; <mx:ComboBox x = '200' color = 'green'> <mx:dataProvider>
combobox
combobox
combobox
combobox
combobox
jsp combobox
jsp combobox  ihave three tables in database country,state and city..if i select one country throug combo box than other combobox show state only select country ...than city how i can implement through jsp   1
ComboBox in Flex4
ComboBox in Flex4: In Flex4 Combobox is called a spark Combobox control. DropDownListBase control is the base class of the combobox control. Combobox control works like a DropDownList control. When we click on the combobox control
editable combobox method selection
editable combobox method selection  how to make an editable combobox that shows nothing initially but as a key is pressed it pops up and selects an item starting with that letter, subsequent keys would keep sorting from the list
how to use an editable combobox
how to use an editable combobox   Hello Everyone!!!!!!!! I have a jcombo box with certain values and i want to use it as an editable that means when user will type something in combobox, according to that text only matching item
fill combobox at runtime jsp
fill combobox at runtime jsp  i have 1 combobox in jsp which... another combobox below it, i want it to be filled on the basis of selected value of 1st combobox...plz help with code
datagrid including combobox
datagrid including combobox  please send datagrid in jsp using mysql database based on id in the datagrid select each record and also update record with available to old values updation is done in form wise. using combo box
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... in text fields and then updation is made in these textboxes and then updation query
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... in text fields and then updation is made in these textboxes and then updation query
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... in text fields and then updation is made in these textboxes and then updation query
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... in text fields and then updation is made in these textboxes and then updation query
two linked combobox
two linked combobox  give jsp example of two combo box when i select state in one combobox in second combo box cities will display according to state which i select
doubt in combobox in flex - XML
doubt in combobox in flex  hi, i have doudt in combobox in flex which is a combination of mxml and actioscript . In my project i has a combobox with 10 items when i select the particular item i has 2 display
combobox cannot be resolved in JavaFX
combobox cannot be resolved in JavaFX  I want to design one application with a combobox containing items. and while selecting i want to give user autocomplete suggestion. but while doing this combobox is not getting resolved. i
values in combobox - Java Beginners
values in combobox  how to fill values in combo box i.e. select tag in html using javascript?   Hi Friend, Try the following code: ComboBox var arr = new Array(); arr[0] = new Array("-select-"); arr[1
ComboBox ItemRenderer in DataGrid
ComboBox ItemRenderer in DataGrid  Hi..... How can I create custom combo box itemtenderer in the flex datagrid? please give me an example.....ADS...; <mx:ComboBox > <mx
Combobox program - Java Beginners
Combobox program  import javax.swing.*; import java.awt.*; public class SwingFrame1 { public static void main(String[] args) throws Exception... in combobox a new text box have to open beside that combo box..  Hi
Combobox jsp from 0 to 10
Combobox jsp from 0 to 10  Hi guys please help me to write a very easy program using jsp to display value in combobox from 0 to 10. How to write the for loop? Please help.Thank!!!   <html> <select> <
FLEX 3 Combobox - Development process
and just started tinkering with Adobe Flex. I have downloaded your combobox... a combobox - once selected - it will show the airport code into a text field. Example: ComboBox Chicago,Illinois Boise, Idaho Buffalo, New York Baltmore
how to select second combobox value .
how to select second combobox value .  I requirement is , i have two combo box, i am selected first combo box value then automatically second combo box value show ,But this both combo box value i retrieves in database. please
Java Swing dynamic Combobox
Java Swing dynamic Combobox In this section, you will learn how to display the data in one combobox related to another combobox. For this, we have created two combo boxes. In the first combobox, we have added four items. When the user
How to Connect J ComboBox with Databse - Java Beginners
How to Connect J ComboBox with Databse  How to Connect J ComboBox with Databse  Hi Friend, Do you want to get JComboBox values from database?Please clarify this. Thanks
Combobox in HTML
Combobox in HTML is used to display a drop-down list of some options from which one can be selected. <select> tag is supported in all the web browsers... the options in the list.ADS_TO_REPLACE_1 Here is how to make a simple Combobox
Example of struts2.2.1 combobox tag.
Example of struts2.2.1 combobox tag. In this tutorial, you will see the implementation of struts2.2.1 combobox tag. The combobox is basically an HTML INPUT... it in directly in the text field.  Directory structure of combobox tag
jsp updation - Development process
how to insert the selected item of combobox in mysql - XML
how to insert the selected item of combobox in mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... of combobox in mxml.how to insert selecteditem in database. pls suggest me i have
java code using combobox,radiobutton,checkbox
java code using combobox,radiobutton,checkbox  hi, send me java code for entering student details into ms access database, the code should includes combo box,radiobutton and checkboxes pl send as early as possible
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from combobox on the web page  Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Java ComboBox in JOptionPane
Java ComboBox in JOptionPane In this section, you will learn how to create combo box in JOptionPane dialog box. We have created a button to perform an action.On clicking the button, you will get the dialog box with combo box in it. 
Jdbc Login Page Validation using Combobox
want to login by validating with combobox....The link which you send its.......please help me i dont know how to validate the combobox for diffrent cities please help me by validating with combobox.... <form action
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.  I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid
Non-edit Combobox with auto fill - Swing AWT
Non-edit Combobox with auto fill  Hi, I have a non-edit JCombobox with auto fill capability. Auto fill is working only for the first character typed by the user. For example, ["Callisto", "Charls", "chim"] are the data
Java swing: get selected value from combobox
Java swing: get selected value from combobox In this tutorial, you will learn how to get selected value from combobox. The combobox provides the list... of programming languages to the combobox using addItem() of JComboBox class. We have

Ads