Refreshing contents of a ComboBox while it is still visible


I have implemented a ComboBoxModel that is populated based on data from a database:
public abstract class DatabaseComboBoxModel extends AbstractListModel implements ComboBoxModel { public static final String CHOOSE_ONE = "(Choose one)"; private SQLUtil sqlUtil; private List list = new ArrayList(); private int selectedIndex = -1; /** * Creates a new instance of DatabaseComboBoxModel. */ public DatabaseComboBoxModel(SQLUtil sqlUtil) throws SQLException { this.sqlUtil = sqlUtil; //this.refreshModel(); } public void refreshModel() throws SQLException { this.list.clear(); this.sqlUtil.setSQL(this.getSQLString()); this.setSQLParameters(this.sqlUtil); ResultSet rs = this.sqlUtil.executeQuery(); while (rs.next()) { DatabaseRecord data = this.getDatabaseRecord(rs); this.list.add(data); } } protected abstract String getSQLString(); protected abstract void setSQLParameters(SQLUtil sqlUtil) throws SQLException; protected abstract DatabaseRecord getDatabaseRecord(ResultSet rs) throws SQLException; public Object getElementAt(int param) { if (param == 0) { return CHOOSE_ONE; } else { return list.get(param - 1); } } public Object getSelectedItem() { if (this.selectedIndex == -1) { return CHOOSE_ONE; } else { return this.list.get(this.selectedIndex); } } public int getSize() { return this.list.size() + 1; } public void setSelectedItem(Object obj) { if (CHOOSE_ONE.equals(obj)) { this.selectedIndex = -1; } else { this.selectedIndex = this.list.indexOf(obj); } } public abstract class DatabaseRecord { private int id; public DatabaseRecord(int id) { this.id = id; } public int getID() { return this.id; } public abstract String toString(); } }
Posted On: Wednesday 3rd of October 2012 12:28:11 AM Total Views:  146
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




problem with jcombobox

hey you all, i have combobox with big list and when i drag the list back and forth the list get messed up. what i have to do in order to avoid this
VIEWS ON THIS POST

300

Posted on:

Wednesday 19th September 2012
View Replies!

Printing the contents of arraylist in JTextArea

I have an arraylist of string type and I want to print the contents of that arraylist in a jtextarea using its settext method. but jTextArea only accepts string Objects.
VIEWS ON THIS POST

145

Posted on:

Friday 21st September 2012
View Replies!

no repaint while resizing when using .setPaint(gradient)

hello as soon a i use gradients in my code, the repaint isn't done while resizing i get something like that while resizing (black rectangles where it has been resized, see below). And when i stop resizing, everything is drawn again, but only then. if i don't use g2d.setPaint(gradient); i have a quick redraw public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; //sample of the code GradientPaint gradient = new GradientPaint(startX, startY, greyColor1, endX, endY, new Color(120,120,120)); g2d.setPaint(gradient); g.drawLine(i, startY, i, endY); }
VIEWS ON THIS POST

168

Posted on:

Friday 21st September 2012
View Replies!

Text from txtfield in txt file and from file to combobox

Hi! Need help again ... I've made application that send email. import java.io.*; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class aljiMailove extends javax.swing.JFrame { public aljiMailove() { initComponents(); } // private void initComponents() { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jPasswordField2 = new javax.swing.JPasswordField(); jLabel2 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jTextField2 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jTextField3 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); jComboBox2 = new javax.swing.JComboBox(); jComboBox3 = new javax.swing.JComboBox(); jComboBox4 = new javax.swing.JComboBox(); jComboBox5 = new javax.swing.JComboBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel2.setText("Password"); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); jLabel3.setText("Subject:"); jLabel4.setText("Username"); jLabel5.setText("Message:"); jButton1.setText("Send!"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel1.setText("Za:"); jLabel6.setText("Od:"); BufferedReader out; try{ out=new BufferedReader(new FileReader("user.txt")); String b=out.readLine(); System.out.println(b); } catch (IOException e2) { e2.printStackTrace(); } jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"Username 1","username2","etc." })); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pass1", "Pass2", "etc." })); jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "for1", "for2", "etc." })); jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "from1", "from2", "etc." })); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jLabel4) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addComponent(jLabel6)) .addGap(33, 33, 33) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPasswordField2, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(178, 178, 178) .addComponent(jButton1))) .addContainerGap(89, Short.MAX_VALUE)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(8, 8, 8) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6) .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButton1)) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(23, 23, 23)) ); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 9, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { final String user=jTextField3.getText(); final String pass=jPasswordField2.getText(); String naslov=jTextField2.getText(); String za=jTextField1.getText(); String od=jTextField4.getText(); String tekst=jTextArea1.getText(); Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(user,pass); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(od)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(za)); message.setSubject(naslov); message.setText(tekst); Transport.send(message); } catch (MessagingException e) { throw new RuntimeException(e); } } public static void main(String args[]) { // /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(aljiMailove.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(aljiMailove.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(aljiMailove.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(aljiMailove.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new aljiMailove().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox2; private javax.swing.JComboBox jComboBox3; private javax.swing.JComboBox jComboBox4; private javax.swing.JComboBox jComboBox5; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPasswordField jPasswordField2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; // End of variables declaration }
VIEWS ON THIS POST

119

Posted on:

Saturday 22nd September 2012
View Replies!

How do I change the "BOLD" property of the contents of a text-field at run-time in JAVA ?

I am doing this program where there are around 20 text-fields which are initially configured to BOLD in design time. At run-time, the user fills out some of the text-fields out of the given 20. Based on that value, there will be some mathematics upon which the rest fields will be filled at run-time. So, what I want is once the user finished and initiates an event , the empty text-fields BOLD property should go to PLAIN instead of "BOLD". I do not want to change anything else( font , color , etc. ). Just want the BOLD propery to go from "BOLD" to "PLAIN" !!! Plzzz Help............ !!!
VIEWS ON THIS POST

155

Posted on:

Saturday 22nd September 2012
View Replies!

Issue while loading images packaged in jar

I have used icons for buttons in my applications.Below code is able to load images when it is run from IDE(eclipse). But when I package everything in a jar file the images are not getting loaded. Find the attachment to view the jar contents. Can you please let me know what should I do to load those images packaged inside jar file I'm using the below code. JButton menuButton=null; menuButton= PMUtil.createMenuButton(..,"monitor.png",..,..,..)
VIEWS ON THIS POST

239

Posted on:

Saturday 22nd September 2012
View Replies!

Issue while loading images.

Please find the below code.Please let me know what changes shall I make to load the images.PFA below the project structure. package tst; import java.awt.GridLayout; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Starter extends JFrame{ public Starter(){ this.getContentPane(); this.setLayout(new GridLayout(1,1)); JPanel jPanel=new JPanel(); JButton jButtonDeploy=new JButton(); JButton jButtonMonitor=new JButton(); JButton jButtonRepo=new JButton(); JButton jButtonPM=new JButton(); URL imgURL=this.getClass().getResource("./images/deploy.png"); if(imgURL !=null){ jButtonDeploy.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } imgURL=this.getClass().getResource("repo.png"); if(imgURL !=null){ jButtonRepo.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } imgURL=this.getClass().getResource("images/monitor.png"); if(imgURL !=null){ jButtonMonitor.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } ClassLoader cl = this.getClass().getClassLoader(); imgURL=cl.getResource("PM.png"); if(imgURL !=null){ jButtonPM.setIcon(new ImageIcon(imgURL)); }else{ System.out.println("resources not found"); } jPanel.setLayout(new GridLayout(4,1)); jPanel.add(jButtonDeploy); jPanel.add(jButtonMonitor); jPanel.add(jButtonRepo); jPanel.add(jButtonPM); this.add(jPanel); } public static void main(String[] args) { Starter tst=new Starter(); tst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tst.setVisible(true); tst.setSize(230,300); } }
VIEWS ON THIS POST

187

Posted on:

Saturday 22nd September 2012
View Replies!

jcombobox is not auto updating with database.

hello all, i have a problem, actually i have posted this problem earlier, and michael dunn helps me solve that problem. Below is the problem. http://www.coderanch.com/t/579226/GUI/java/auto-update-jcombobox but now i m getting the same problem in auto updating jcomboboxes. i have two code one is updating jcombobox with arraylist, and working properly. one is with db that is not working. code for both are same, instead of arraylist i am just using database. i also have done debugging by putting bunch system.out.println to check the flow, both giving the same sequence of statements, i mean flow of both are same. i don't know what wrong is going there, can anyone please help me in that. below is the code with db which is not working. import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; import java.sql.*; class Display { CardLayout cl = new CardLayout(); JPanel cardPanel = new JPanel(cl); JPanel panel = new JPanel(); JTextField tf = new JTextField(15); ArrayList resultSetList = new ArrayList(); JButton btn = new JButton("Add Student"); JFrame frame = new JFrame(); JComboBox studentNames = new JComboBox(); DefaultComboBoxModel dcm = new DefaultComboBoxModel(); LoadStudents ls = new LoadStudents(); SaveStudent ss = new SaveStudent(); Display1 d1 = new Display1(); public Display() throws SQLException { System.out.println("Inside WithArrayList Constructor"); cardPanel.add(panel,"display"); cardPanel.add(d1.panel1,"display1"); panel.add(tf); panel.add(btn); frame.add(cardPanel); frame.setVisible(true); frame.setSize(200,100); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try{ System.out.println("Inside WithArrayList ActionListener"); String values = tf.getText(); ss.saveStudent(values); System.out.println("Inside WithArrayList ActionListener after savestudent"); tf.setText(""); System.out.println("Inside WithArrayList ActionListener Before d1.update"); d1.update(); System.out.println("Inside WithArrayList ActionListener After d1.update"); cl.show(cardPanel,"display1"); }catch(Exception e){} } }); } public static void main(String args[]) throws SQLException{new Display();} class Display1 { JPanel panel1 = new JPanel(); JComboBox studentNames = new JComboBox(); DefaultComboBoxModel dcm = new DefaultComboBoxModel(); LoadStudents ls = new LoadStudents(); SaveStudent ss = new SaveStudent(); public Display1() throws SQLException { System.out.println("Inside Constructor Display1"); ls.loadStudents1(studentNames); System.out.println("Inside Constructor Display1 After Calling ls.loadStudents1"); panel1.add(studentNames); } public void update() throws SQLException { System.out.println("Inside Update method of Display1 class"); ls.loadStudents1(studentNames); System.out.println("Inside Update method of Display1 class After Calling loadstudents1"); } } class LoadStudents { DefaultComboBoxModel model; public void loadStudents1(JComboBox cbo) throws SQLException { System.out.println("Inside loadStudents1 of class LoadStudents Beginning"); ArrayList ress; Db db = new Db(); model = new DefaultComboBoxModel(); ress = db.NameValues(); ListIterator iter = ress.listIterator(); while (iter.hasNext()) { model.addElement(iter.next()); } cbo.setModel(model); System.out.println("Inside loadStudents1 of class LoadStudents End"); } } class SaveStudent { public void saveStudent(String values) throws SQLException { System.out.println("Inside saveStudent of class saveStudent Beginning"); Db db = new Db(); db.Insert1(values); System.out.println("Inside saveStudent of class saveStudent End"); } } class Db { public ArrayList NameValues()throws SQLException{ System.out.println("Inside NameValues of class Db Beginning"); Statement ps; ResultSet res; String query = "SELECT names FROM studentregistration"; DbConnection dbconn = new DbConnection(); Connection conn = dbconn.dbConn(); ps = conn.createStatement(); res = ps.executeQuery(query); while(res.next()){ resultSetList.add(res.getString("names")); } return resultSetList; } public void Insert1(String nm) { try{ PreparedStatement st; String query = "INSERT into studentregistration (names) VALUES ()"; DbConnection dbconn = new DbConnection(); Connection conn = dbconn.dbConn(); st = conn.prepareStatement(query); st.setString(1,nm); int rr = st.executeUpdate(); System.out.println("Inside Insert1 of class Db Beginning"); }catch(Exception e){e.printStackTrace();} } } }
VIEWS ON THIS POST

204

Posted on:

Monday 24th September 2012
View Replies!

Text in Jcombobox is too small, but why?

, As you can see the text in the JCombobox is to small, but I don't know why. I also tryed jCombobox_test.setpreferedsize() and setSize() but it both doesn't work And in another GUI of me I had this, and that is what I'm looking for:
VIEWS ON THIS POST

124

Posted on:

Monday 24th September 2012
View Replies!

Problem while creating jpg image

i am trying to create a jpg image with some word printed like "hello world" in the image.I dont know how to change the font size of the text .I am getting the output but if i increase the size of the buffredimage the "hello world" word is hardly visible. I have another doubt ,as to how to change the background image color. Right now i am getting a jpg image with black background and hello world text in blue . package image; import java.io.*; import java.awt.*; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; public class creategraphics { public static void main(String[]args) { BufferedImage image=new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB); Graphics g=image.createGraphics(); g.setColor(Color.blue); g.drawString("World", 25,25); try{ ImageIO.write(image,"jpg",new File("c://createdimage.jpg")); } catch (IOException e) { e.printStackTrace(); } } }
VIEWS ON THIS POST

98

Posted on:

Monday 24th September 2012
View Replies!

how to auto update jcombobox?

i have a application, which has one registration panel, and one search panel.. i have a menu and on click of that menu i m changing the jpanel (registration or search). on the search page i have one combo which displaying all the names of students who are registered or exist in the database. but when i register a student and than click on search menu, it wiill not update the combo box, i mean the recently registered student is not appear in the list until i restart my application. what i need to do to update the combo box automatically\t
VIEWS ON THIS POST

202

Posted on:

Tuesday 25th September 2012
View Replies!

JTable not refreshing with fireTableDataChanged

After values have been added into the database, the JTable does not display the new data unless I terminate and execute the program again. Am I supposed to use fireTableDataChanged or newDataAvailable I'm using DefaultTableModel: DefaultTableModel tableModel = new DefaultTableModel(data,columnNames); JTable table = new JTable (tableModel);
VIEWS ON THIS POST

214

Posted on:

Tuesday 25th September 2012
View Replies!

problem in fetching values in combobox from databases.

hello, i m storing date in string format in database, actually i have created three JComboBoxes for Date, month, year. and i m just appending all the values of all comboboxes before inserting into databases and then inserting into database. now i need to fetch values from database and display in their combo boxes (i mean: date should be in date combo, month should be in month, so on..) how can i do this although i have not added any delimiter to string, so how do i split the string so i got respective values in respective comboboxes
VIEWS ON THIS POST

171

Posted on:

Tuesday 25th September 2012
View Replies!

problem while selecting radio buttons

Hi .. I'm trying to develop a small program using swing which is supposed to work as follows.. upon selecting first radio the dialog box should show RED...upon selecting the second radio button, the dialog box should show YELLOW...and WHITE for the third radio button... But,I'm confused because for the first click on any of the 3 radiobuttons the app. works fine and shows only one dialog box, but as soon as the second Radio button is clicked ,lets say, the one named RED after clicking WHITE.... 2 dialog boxex appear, one hidden behind another...one showing WHITE...otherone showing RED...but it should display only one dialog box.... the code is: import java.awt.*; import java.awt.event.*; import javax.swing.*; /**/ public class RadioButton1 extends JApplet implements ItemListener { private Container Panel; private LayoutManager Layout; private JRadioButton Red; private JRadioButton Yellow; private JRadioButton White; private ButtonGroup Background; public RadioButton1 () { /* Instantiation */ Layout = new FlowLayout (); Panel = getContentPane (); Red = new JRadioButton ("Red",false); Yellow = new JRadioButton ("Yellow", false); White = new JRadioButton ("white"); Background = new ButtonGroup(); /* Location */ Panel.setLayout (Layout); Panel.add (Red); Panel.add (Yellow); Panel.add (White); /* Decoration */ Red.setBackground (Color.red); Yellow.setBackground (Color.yellow); White.setBackground (Color.white); White.setForeground (Color.red); /* Configuration */ Background.add (Red); Background.add (Yellow); Background.add (White); Red.addItemListener (this); Yellow.addItemListener (this); White.addItemListener (this); } public void itemStateChanged (ItemEvent e) { Object Source; Source = e.getSource(); if(Source==Red) JOptionPane.showMessageDialog(Red,"I'm RED"); else { if(Source==Yellow) JOptionPane.showMessageDialog(Yellow,"I'm YELLOW"); else { if(Source==White) JOptionPane.showMessageDialog(White,"I'm WHITE"); } } } }
VIEWS ON THIS POST

142

Posted on:

Wednesday 26th September 2012
View Replies!

problem while creating sliding panel

i m trying to add Sliding Panel, it works for me, but i have few problems in that: when i am hovering over frame, it showing me the sliding panel, and when i am hovering out to the frame it disappears, but when i am hovering over my sliding panel, my sliding panel blinking and sometimes gets disappears. the second problem is i want it to be transparent, and i used setOpaque(false), but it's not working. the third problem is i want when i hover over frame, my sliding panel should appear with some effects, (like the SlideToggle effect of jQuery, SlideToggle). how can i do this\t here is my code: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; public class SlidingPanel extends JFrame{ JPanel panelMain = new JPanel(); JPanel panelSlider = new JPanel(); public SlidingPanel() { JSlider slider1 = new JSlider(); slider1.setBorder(BorderFactory.createTitledBorder("Oxygen Level")); JSlider slider2 = new JSlider(); slider2.setBorder(BorderFactory.createTitledBorder("Food")); JSlider slider3 = new JSlider(); slider3.setBorder(BorderFactory.createTitledBorder("Water Level")); JSlider slider4 = new JSlider(); slider4.setBorder(BorderFactory.createTitledBorder("Nitrogen Level")); panelSlider.setLayout(new BoxLayout(panelSlider, BoxLayout.Y_AXIS)); panelSlider.add(slider1); panelSlider.add(slider2); panelSlider.add(slider3); panelSlider.add(slider4); panelMain.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseExited(MouseEvent e) { panelSlider.setVisible(false); panelSlider.repaint(); panelSlider.revalidate(); } public void mouseEntered(MouseEvent e) { panelSlider.setVisible(true); panelSlider.repaint(); panelSlider.revalidate(); } public void mouseClicked(MouseEvent e) {} }); panelMain.setLayout(new BorderLayout()); panelMain.add(panelSlider, BorderLayout.EAST); this.add(panelMain); panelSlider.setVisible(false); this.setSize(1280,550); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String agrs[]) { new SlidingPanel(); } }
VIEWS ON THIS POST

122

Posted on:

Wednesday 26th September 2012
View Replies!

refreshing JFrame?

everybody, I have a JFrame with a grid layout on it, each grid has a button. What I'm trying to do is remove all the buttons when a button is pushed. I believe I have it correct except that the JFrame won't refresh the revised panel. Advice Also, I noticed on some sites that people were able to paste their code in with lined numbers to make referencing it easier. Anyone know how i can do that to make it easier on you all to read
VIEWS ON THIS POST

91

Posted on:

Wednesday 26th September 2012
View Replies!

AWT Component Loading Issue After Accessing it for a while

I've a AWT Java application which is accessible by a JSP page. JSP pages are deployed in a web application and AWT classes are inside a Java application. Both web and Java is bundled in an ear file which is installed on an IBM websphere application server 7. AWT application is launched by a JSP login page. There are different buttons in that AWT app to access different functionalities of the application. They all makes database call (simple CRUD operation) to save/update database record. When multiple user (5 user) log in to the system with their credentials, after sometime, AWT application stops responding. Application starts hanging/freezing after sometime. When you click on one functionality, the child frame does not paint correctly and due to this, input form fields of child frame does not load. You have to close the AWT main window and then re-login to access the AWT application. We're not able to replicate this with single user. We've then tested it with 4 user and there was no issue. When we've increased user to 5 i.e., 5 users concurrently accessing AWT application, then we have got this screen freezing problem (child frame components not loading correctly after sometime of access). Does anyone have faced this issue in AWT Any idea how to approach and find the root cause for this.
VIEWS ON THIS POST

62

Posted on:

Wednesday 26th September 2012
View Replies!

Trying to Center the contents of a Label

Hi folks, The label lblreceipe1 contains the String keyIngrediants. The problem I have is that the String automatically goes to the left. How can I centre this in the label
VIEWS ON THIS POST

61

Posted on:

Thursday 27th September 2012
View Replies!

Help with combobox and pop window

Hi i have a combobox and when i click on add button another frame pop up with text field(name ,address etc..) ,confirm button and cancel button at bottom of the frame. When i put something on the second window and click confirm i would have the information on the combo box. i don't really know how to doing it import javax.swing.*; import java.awt.event.*; import java.util.*; public class AddressList{ JComboBox combo; JTextField txtBox; private String PersonViewing; private String TelephoneNumber; private String Address; private JFrame Addressframe; Address Alist; /** * Return the name of person that are viewing the property */ public String getName() { return PersonViewing; } /** * Return the address of person that are viewing the property */ public String getAddress() { return PersonViewing; } /** * Return the telephone number of person that are viewing the property */ public String getTelephoneNumberOfPerson() { return TelephoneNumber; } public AddressList(){ JFrame frame = new JFrame("Add-Remove item to list"); String items[] = {"", "", "", "", ""}; combo = new JComboBox(items); JButton button1 = new JButton("Add new item"); txtBox = new JTextField(35); button1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Address Alist = new Address(); } }); JButton button2 = new JButton("Remove"); button2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (combo.getItemCount() > 0) combo.removeItemAt(0); else JOptionPane.showMessageDialog(null,"the viewing list is empty "); } }); JPanel panel = new JPanel(); JPanel panel1 = new JPanel(); panel.add(txtBox); panel.add(combo); panel.add(button1); panel.add(button2); frame.add(panel); // frame.add(panel1); frame.setSize(320, 350); frame.setVisible(true); frame.setResizable(false); boolean resizable = frame.isResizable(); } } import javax.swing.*; import java.awt.event.*; import java.util.*; import java.awt.*; public class Address { public Address() { JFrame frame3 = new JFrame("Adding the new propert"); JPanel panel = new JPanel(new GridLayout(4,2,20,30)); panel.add(new JLabel("Name" )); panel.add(new JTextField(5)); panel.add(new JLabel("Telphone")); panel.add(new JTextField(3)); panel.add(new JLabel("Address")); panel.add(new JTextField(3)); panel.add(new JButton("Confirm")); panel.add(new JButton("Cancel")); frame3.add(panel); frame3.setSize(350,350); frame3.setVisible(true); } }
VIEWS ON THIS POST

88

Posted on:

Friday 28th September 2012
View Replies!

How can I show new text in JTextArea while program is executing?

Hi all, first post here, and I most definitely am a greenhorn. I have a program that reads in data from files, and then it analyzes that data, and then spits out an analysis of the data into an html page. This all works just fine. However, sometimes it takes the program a while to analyze the data file, as some of the data files that users read can be rather large. . And, if the data file IS a large file, I want status updates to be sent to the user, so they know the program is not hung. So, the GUI of my program is a JPanel with a TextPanel that has a JTextArea, and that works fine too. That is, for the most part. Because, anytime I 'add' or 'append' text to the area it does work. However, and this is my problem, if the data file IS a large file, my status messages added to the JTextArea do not show up until AFTER the entire file has been analyzed, and by that point they are obviously useless. TextPanel = new JPanel(); TextPanel.setLayout(new BorderLayout()); Text = new JTextArea("blah, blah",x,y); Now, my program has a function where it determines the size of the file that the user specified for it to read. If the file is over a certain size, then it reads in chunks of the file at a time and then does analysis on each chunk, and after all chunks have been analyzed, it puts the file back together and all that works just fine, except for status updates. It is in the part of the code that I want the status updates . . . int numOFbuffers = filesize/buffersize; if (numOFbuffers > 0) { moreData = true; while (numOFbuffers >= 0) { Text.append("\nWorking...\n");
VIEWS ON THIS POST

185

Posted on:

Monday 1st October 2012
View Replies!