JTable disturbs gridbaglayout with jtextfields

Hello, my problem is a JTable, that shrinks my two JTextFields to zero length. I tried to create the gui without the JTable and it works as expected. There should be two JTextFields with fixed length in a row below the JTable in a JTabbedPane. Code:
    jT1 = new JTable( 10,10);
    jSP1 = new JScrollPane( jT1);// without jT1 everything is fine
    jP1 = new JPanel( new BorderLayout());
    jP1.add( jSP1, BorderLayout.CENTER);
    jTP = new JTabbedPane();
    jTP.add( "Tab1", jP1);
    jL1 = new JLabel( "Txt1:");
    jTF1 = new JTextField( "0.00",10);
    jL2 = new JLabel( "Txt2:");
    jTF2 = new JTextField( "0.00",10);
    jP0 = new JPanel(new GridBagLayout());
    jP0.add(jTP, new GridBagConstraints(0, 0, 4, 1, 1.0, 1.0
        ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jP0.add(jL1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
        ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));
    jP0.add(jTF1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
        ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 10, 0, 0), 0, 0));
    jP0.add(jL2, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
        ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 20, 0, 0), 0, 0));
    jP0.add(jTF2, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
        ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 10, 0, 0), 0, 0));Setting weightx to 0.5 and GriBagConstraints.HORIZONTAL for the JTextFields makes them variable size, but that' not what I want.

What about setting iPadx parameter in GridBagConstraints?
regards,
Stas

Similar Messages

  • Using GridBagLayout with JTExtField

    Hello Everybody,
    I use the GridBagLayout to lay out panels, and one of them also uses a GridBag. In this panel there are some textfields. When you type into one of them, that causes the panel's size to change and therefore, it changes sizes of all neighboring panels.
    What can be wrong?
    Here is how I initialize constraints for input fields (and there are also fixed labels before each text field);
    cns.ipady=1;
    cns.ipadx=1;
    cns.weightx=0;
    cns.weighty=0;
    cns.fill = GridBagConstraints.NONE;
    cns.anchor = GridBagConstraints.EAST;
    layout.setConstraints(label, cns);
    and for text fields
    cns.fill = GridBagConstraints.HORIZONTAL;
    cns.gridwidth = GridBagConstraints.REMAINDER;
    cns.weightx=1.0;
    cns.weighty=0;
    layout.setConstraints(tf, cns);
    thanks,
    Sergej.

    Been there myself
    http://forum.java.sun.com/thread.jsp?forum=57&thread=364047

  • Memory problem with JTextFields

    Hello,
    I have a wierd problem with JTextField and the memory.
    I need to fill a JPanel with different Components (including JTextFields), then do some calculation, remove the Components and filling the JPanel again.
    When i so this too often my i get an OutOfMemory Exception. I narrowed to problem down and wrote a small sample program to demonstrate the problem.
    When i call the method doIT (where the Panel is repeatedly filled) from the main-function everything works fine, but when it is called as a result from the GUI-Button-Event the memory for the JTextFields is not freed (even the call of the Garbage collector changes nothing)
    When i only use JButtons to fill the Panel everything works fine.
    Has anyone an idea why this problem occurs and how i can work around it?
    [Edit] I tested it whith java 1.5.0_06, 1.5.0_11, 1.6.0_02
    Thanks
    Marc
    import java.awt.Frame;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.management.ManagementFactory;
    import java.lang.management.MemoryUsage;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class MemoryTestDLG extends JDialog {
         public MemoryTestDLG(Frame owner) {
              // create Dialog with one Button that calls the testMethod
              super(owner);
              JButton b = new JButton("doIT ...");
              b.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        doIT();
                        setVisible(false);
              getContentPane().add(b);
              pack();
         public void doIT() {
              // Testmethod that fills a JPanel 20 times with Components and clears it
              // again
              JPanel p = new JPanel();
              long memUse1 = 0;
              long memUse2 = 0;
              long memUseTemp = 0;
              for (int count = 0; count < 20; count++) {
                   // Clear the panel
                   p.removeAll();
                   // Get memory usage before the task
                   Runtime.getRuntime().gc();
                   memUse1 = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
                             .getUsed();
                   // Fill Panel with components
                   for (int i = 0; i < 200; i++) {
                        // The Buttons seem to be released without any problem
                        p.add(new JButton("test" + Math.random()));
                        // JTextFields are not released when used from the dialog.
                        p.add(new JTextField("test " + Math.random()));
                   // get memory usage after the task
                   Runtime.getRuntime().gc();
                   memUseTemp = memUse2;
                   memUse2 = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()
                             .getUsed();
                   // print Memory results
                   System.out.println("Memory Usage: " + f(memUse1) + "   ->"
                             + f(memUse2) + " [ Used:" + f(memUse2 - memUse1)
                             + " ] [ Freed: " + f(memUseTemp - memUse1) + "]");
         public String f(long m) // formats the output
              String s = "" + m;
              while (s.length() < 8)
                   s = " " + s;
              return s;
         public static void main(String[] args) {
              MemoryTestDLG d = new MemoryTestDLG(null);
              System.out
                        .println("------------------ Direct Call (all is OK) -------------------");
              d.doIT(); // Memory is freed with every call to JPanel.removeAll()
              System.out
                        .println("------------ Call from Dialog (memory is not freed) -------------");
              // The Memory keeps blocked
              d.setModal(true);
              d.setVisible(true);
              System.exit(0);
    }Message was edited by:
    marcvomorc

    Thank you for your answer,
    In this sample the programm does not run out of memory. But when you look at the output you see, that in the first run (direct call) the memory ist freed immediately when tha panel is cleared but in the second run (from the Button) the memory usage is getting bigger and bigger. Wenn you change the number of components to 2000 (4000)
    // Fill Panel with components
            for (int i = 0; i < 2000; i++) {
                // The Buttons seem to be released without any problem
    //... ...and use the default memory settings (69mb heap) the programm runns out of memory.
    I get the following output:
    ------------------ Direct Call (all is OK) -------------------
    Memory Usage:   445504   -> 8121016 [ Used: 7675512 ] [ Freed:  -445504]
    Memory Usage:   617352   -> 8114336 [ Used: 7496984 ] [ Freed:  7503664]
    Memory Usage:   810488   -> 8491768 [ Used: 7681280 ] [ Freed:  7303848]
    Memory Usage:   943704   -> 8114976 [ Used: 7171272 ] [ Freed:  7548064]
    Memory Usage:   836760   -> 8505072 [ Used: 7668312 ] [ Freed:  7278216]
    Memory Usage:   978352   -> 8114784 [ Used: 7136432 ] [ Freed:  7526720]
    Memory Usage:   835552   -> 8498288 [ Used: 7662736 ] [ Freed:  7279232]
    Memory Usage:   977096   -> 8114312 [ Used: 7137216 ] [ Freed:  7521192]
    Memory Usage:   835640   -> 8498376 [ Used: 7662736 ] [ Freed:  7278672]
    Memory Usage:   977296   -> 8115000 [ Used: 7137704 ] [ Freed:  7521080]
    Memory Usage:   835392   -> 8504872 [ Used: 7669480 ] [ Freed:  7279608]
    Memory Usage:   976968   -> 8115192 [ Used: 7138224 ] [ Freed:  7527904]
    Memory Usage:   836224   -> 8501624 [ Used: 7665400 ] [ Freed:  7278968]
    Memory Usage:   977840   -> 8115120 [ Used: 7137280 ] [ Freed:  7523784]
    Memory Usage:   835664   -> 8498256 [ Used: 7662592 ] [ Freed:  7279456]
    Memory Usage:   976856   -> 8114384 [ Used: 7137528 ] [ Freed:  7521400]
    Memory Usage:   835784   -> 8502848 [ Used: 7667064 ] [ Freed:  7278600]
    Memory Usage:   977360   -> 8114592 [ Used: 7137232 ] [ Freed:  7525488]
    Memory Usage:   835496   -> 8502720 [ Used: 7667224 ] [ Freed:  7279096]
    Memory Usage:   976440   -> 8115128 [ Used: 7138688 ] [ Freed:  7526280]
    ------------ Call from Dialog (memory is not freed) -------------
    Memory Usage:   866504   -> 8784320 [ Used: 7917816 ] [ Freed:  -866504]
    Memory Usage:  7480760   ->14631152 [ Used: 7150392 ] [ Freed:  1303560]
    Memory Usage: 14245264   ->22127104 [ Used: 7881840 ] [ Freed:   385888]
    Memory Usage: 19302896   ->27190744 [ Used: 7887848 ] [ Freed:  2824208]
    Memory Usage: 27190744   ->35073944 [ Used: 7883200 ] [ Freed:        0]
    Memory Usage: 31856624   ->39740176 [ Used: 7883552 ] [ Freed:  3217320]
    Memory Usage: 39740176   ->47623040 [ Used: 7882864 ] [ Freed:        0]
    Memory Usage: 44410480   ->52293864 [ Used: 7883384 ] [ Freed:  3212560]
    Memory Usage: 52293864   ->58569304 [ Used: 6275440 ] [ Freed:        0]
    Memory Usage: 58569304   ->64846400 [ Used: 6277096 ] [ Freed:        0]
    Exception occurred during event dispatching:
    java.lang.OutOfMemoryError: Java heap spacewhen I outcomment the adding of the JButtons the amount of freed memory is 0 in the second run. So my guess is, that there is a problem with freeing the memory for the JTextFields.
    Memory Usage:   447832   -> 6509960 [ Used: 6062128 ] [ Freed:  6332768]
    Memory Usage:   722776   -> 6785632 [ Used: 6062856 ] [ Freed:  5787184]
    ------------ Call from Dialog (memory is not freed) -------------
    Memory Usage:   468880   -> 6770240 [ Used: 6301360 ] [ Freed:  -468880]
    Memory Usage:  6770240   ->13016264 [ Used: 6246024 ] [ Freed:        0]
    Memory Usage: 13016264   ->19297080 [ Used: 6280816 ] [ Freed:        0]
    Memory Usage: 19297080   ->25570152 [ Used: 6273072 ] [ Freed:        0]
    Memory Usage: 25570152   ->31849160 [ Used: 6279008 ] [ Freed:        0]
    Memory Usage: 31849160   ->38124368 [ Used: 6275208 ] [ Freed:        0]
    Memory Usage: 38124368   ->44402072 [ Used: 6277704 ] [ Freed:        0]
    Memory Usage: 44402072   ->50677928 [ Used: 6275856 ] [ Freed:        0]
    Memory Usage: 50677928   ->56955880 [ Used: 6277952 ] [ Freed:        0]
    Memory Usage: 56955880   ->63232152 [ Used: 6276272 ] [ Freed:        0]
    Exception occurred during event dispatching:
    java.lang.OutOfMemoryError: Java heap spaceAdditionally the JPanel I am using is not displayed on the screen. It stays invisible the whole time, but i cannot work around that, because the calculation is depending on the values being in components on the JPanel)
    Marc

  • Displaying JTable using GridBagLayout

    Hii Javaties
    I am displaying all my GUI using GridBagLayout Manager.
    But i dont know , how to add a JTable using GridBagLayout manager.
    I[b] want tht each column of the JTable be displayed in each cell .
    i.e column 1 should be displayed at position 1,4
    Can anybody guide me .
    Thanx

    Perhaps what you are looking for is Custom Editors or Renderers?

  • How to Populate the JTable Object programatically with SQL Results

    I'm wondering if someone could help me on how to populate the JTable Object with SQL Results wherein the Row of tjhe JTable object is automatically adjusted depending on how many records you have queried.
    Thanks in advance and God bless! (",)
    * frmMain.java
    * Created on October 4, 2006, 6:15 AM
    package tds;
    import java.io.*;
    import java.awt.Toolkit;
    import javax.swing.JFrame;
    import javax.imageio.*;
    import javax.swing.JFrame;
    import java.sql.*;
    import javax.swing.table.DefaultTableModel;
    * @author Dexter.Carlit
    public class frmMain extends javax.swing.JFrame {
    private Connection connection = null;
    private DefaultTableModel model;
    /** Creates new form frmMain */
    public frmMain() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
    jSplitPane = new javax.swing.JSplitPane();
    jScrollPane1 = new javax.swing.JScrollPane();
    jPanel3 = new javax.swing.JPanel();
    jScrollPane2 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    jPanel1 = new javax.swing.JPanel();
    jPanel4 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jTextField3 = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    jTextField4 = new javax.swing.JTextField();
    jPanel5 = new javax.swing.JPanel();
    jScrollPane3 = new javax.swing.JScrollPane();
    jGrid = new javax.swing.JTable();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jProgressBar1 = new javax.swing.JProgressBar();
    jPanel2 = new javax.swing.JPanel();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowOpened(java.awt.event.WindowEvent evt) {
    formWindowOpened(evt);
    getAccessibleContext().setAccessibleName("frmMain");
    jSplitPane.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    jSplitPane.setDividerLocation(200);
    jSplitPane.setDividerSize(10);
    jScrollPane2.setViewportView(jTree1);
    org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel3Layout.createSequentialGroup()
    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 916, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    jPanel3Layout.setVerticalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
    jScrollPane1.setViewportView(jPanel3);
    jSplitPane.setLeftComponent(jScrollPane1);
    jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
    jLabel1.setText("First Name:");
    jLabel2.setText("Last Name:");
    jLabel3.setText("Position :");
    jLabel4.setText("Department:");
    jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Search Results"));
    jGrid.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
    new String [] {
    "LName", "FName", "Position", "Department", "Office No", "Local No", "Office Mobile No", "Home No", "MobileNo", "Email Address"
    jGrid.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    jGrid.setColumnSelectionAllowed(true);
    jGrid.setName("");
    jGrid.setTableHeader(jGrid.getTableHeader());
    jScrollPane3.setViewportView(jGrid);
    jScrollPane3.getAccessibleContext().setAccessibleName("rset");
    org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
    jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
    jPanel5Layout.setVerticalGroup(
    jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
    jButton1.setText("Find");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    jButton1MouseClicked(evt);
    jButton2.setText("Clear");
    jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    jButton2MouseClicked(evt);
    org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
    jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4Layout.createSequentialGroup()
    .add(jLabel1)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE))
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4Layout.createSequentialGroup()
    .add(jLabel2)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
    .add(1, 1, 1))
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4Layout.createSequentialGroup()
    .add(jLabel3)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jLabel4)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE))
    .add(jPanel4Layout.createSequentialGroup()
    .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
    .addContainerGap())
    jPanel4Layout.linkSize(new java.awt.Component[] {jButton1, jButton2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
    jPanel4Layout.setVerticalGroup(
    jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel4Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jLabel1)
    .add(jTextField1))
    .add(18, 18, 18)
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jLabel2)
    .add(jTextField2))
    .add(16, 16, 16)
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jLabel3)
    .add(jTextField3)
    .add(jLabel4)
    .add(jTextField4))
    .add(14, 14, 14)
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jProgressBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
    .addContainerGap())
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    jTabbedPane1.addTab("Search", jPanel1);
    org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 458, Short.MAX_VALUE)
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 401, Short.MAX_VALUE)
    jTabbedPane1.addTab("Directory", jPanel2);
    jSplitPane.setRightComponent(jTabbedPane1);
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jSplitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jSplitPane)
    pack();
    }// </editor-fold>//GEN-END:initComponents
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    }//GEN-LAST:event_jButton1ActionPerformed
    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
    jGrid.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
    {null, null, null, null, null, null, null, null, null, null},
    {null, null, null, null, null, null, null, null, null, null},
    {null, null, null, null, null, null, null, null, null, null},
    {null, null, null, null, null, null, null, null, null, null}
    new String [] {
    "LName", "FName", "Position", "Department", "Office No", "Local No", "Office Mobile No", "Home No", "MobileNo", "Email Address"
    jGrid.updateUI();
    }//GEN-LAST:event_jButton2MouseClicked
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
    try {
    //Load and register SQL Server driver
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    //Establish a connection
    Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://X.X.X.X:1433","MyAccount","MyPassword");
    //Create a Statement object
    Statement sql_stmt = connection.createStatement();
    //Create a ResultSet object, execute the query and return a
    // resultset
    ResultSet rset = sql_stmt.executeQuery("SELECT * FROM EpxDirectory..Directory Order By LName");
    // Populates a JTABLE Object
    int i=0;
    while (rset.next()){
    String LName = rset.getString(1);
    String FName = rset.getString(2);
    String Position = rset.getString(3);
    String Dept_Code = rset.getString(4);
    String OffPhoneNo = rset.getString(5);
    String LocalNo = rset.getString(6);
    String OffMobileNo = rset.getString(7);
    String HomePhoneNo = rset.getString(8);
    String MobileNo = rset.getString(9);
    String Email = rset.getString(10);
    jGrid.updateUI();
    jGrid.setValueAt(rset.getString(1).trim(),i,0);
    jGrid.setValueAt(rset.getString(2).trim(),i,1);
    jGrid.setValueAt(rset.getString(3).trim(),i,2);
    jGrid.setValueAt(rset.getString(4).trim(),i,3);
    jGrid.setValueAt(rset.getString(5).trim(),i,4);
    jGrid.setValueAt(rset.getString(6).trim(),i,5);
    jGrid.setValueAt(rset.getString(7).trim(),i,6);
    jGrid.setValueAt(rset.getString(8).trim(),i,7);
    jGrid.setValueAt(rset.getString(9).trim(),i,8);
    jGrid.setValueAt(rset.getString(10).trim(),i,9);
    i++;
    //Close the ResultSet and Statement
    rset.close();
    sql_stmt.close();
    //Close the database connection
    connection.close();
    System.out.println(Integer.toString(i) + " rows found");
    } catch(Exception e) {
    System.out.println("Failed to connect; Please view Stack Trace");
    e.printStackTrace();
    }//GEN-LAST:event_jButton1MouseClicked
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    }//GEN-LAST:event_formWindowOpened
    public static void run(){
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    frmMain frmMain = new frmMain();
    frmMain.setLocationRelativeTo(null); // Center the JFrame on the
    frmMain.setVisible(true);
    private void exitApplication() {
    // try {
    // //gui.putStatus("Closing the connection....please wait.....");
    // if(connection != null) {
    // // connection.close(); //Closing the connection object.
    // } catch(SQLException ex) { //Trap SQLException
    // //gui.putStatus(ex.toString());
    System.exit(0); //Exit the aplication
    * @param args the command line arguments
    public static void main(String args[]) {
    run();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JTable jGrid;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSplitPane jSplitPane;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTree jTree1;
    // End of variables declaration//GEN-END:variables
    }

    Use code tags.
    Don't mix GUI and JDBC together. Split them out into separate classes.
    You have a good start, but you will need to loop through your resultset and also pull the ResultSet metaData for you column headings

  • Is it a bug? GridBagLayout  with textField

    Hi,
    The following method does not work fine.
    The textfield field gets all the space
    but if i change
    JTextField field = new JTextField();
    with
    JPanel field = new JPanel();
    it will work fine.
    I think there is a problem with GridBagLayout
    and textField. is it a bug in jdk1.2
    public JPanel getCPane() {
    int XUNIT = 5;
    int YUNIT = 100;
    JPanel pane = new JPanel();
    JPanel pane1 = new JPanel();
    JTextField field = new JTextField();
    pane1.setBackground(Color.red);
    pane1.setPreferredSize(new Dimension(2*XUNIT, YUNIT));
    field.setPreferredSize(new Dimension(6*XUNIT, YUNIT));
    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(0,0,0,0);
    c.weightx = c.weighty = 0;
    c.gridx = 0; c.gridy = 0;
    c.gridwidth = 2*XUNIT; c.gridheight = YUNIT;
    pane.add(pane1, c);
    c.weightx = c.weighty = 1;
    c.gridx = 2; c.gridy = 0;
    c.gridwidth = 6*XUNIT; c.gridheight = YUNIT;
    pane.add(field, c);
    return pane;

    Any solution please

  • Real Model View Controller with JTextField

    Hi!
    I am new to Java (so please bear with me). I am building a swing application. I already have added a JTable with a corresponding table model that extends AbstractTableModel. Rather than store the data in the table model, I have modified setValueAt and getValueAt to write and read cell data to another location. So far, everything is fine. When doing setValueAt, I have a fireTableCellUpdated statement that I use to update the edited cell. So far, things are all still fine.
    I would like to do the same thing with a JTextField. I found an example in Core Java Volume 1 for create a class that extends PlainDocument. It uses insertString to update the document in a way that ensures that only numbers are entered. I implemented this. Everything is still fine. I changed insertString to update my remote repository (a field in another class). Everything is still fine. Next, I tried to change (override) both getText methods to read from the repository. This works, but is not reflected on the screen.
    I realize that I need the equivalent of a fireTableCellUpdated statement for the class that extends PlainDocument, but do not know how to do this.
    I have looked a lot over the internet for the model view controller implementation. I know that it can be done using event and event listeners, but this seems to defeat the purpose of the model view controller - it seems like you ought to be able to directly modify the model object to access external data.
    My code is below.
    Thanks/Phil Troy
    * PlainDocument class to make it possible to:
    * - Make sure input in unsigned integer
    * - Automatically save data to appropriate locate
    * This will hopefully eventually work by overriding the insertString and getText methods
    * and creating methods that can be overridden to get and save the numerical value
    class UnsignedIntegerDocument extends PlainDocument
         TutorSchedulerPlusSettings settings;
         JTextField textField;
         public UnsignedIntegerDocument(TutorSchedulerPlusSettings settings)
         {     super();
              this.settings = settings;
         public void setTextField(JTextField textField)
         {     this.textField = textField;
         // Overridden method
         public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
         {     if (str == null) return;
              String oldString = getText(0, getLength());
              String newString = oldString.substring(0, offs) + str +oldString.substring(offs);
              try
              {     setValue(Integer.parseInt(newString));
                   super.insertString(offs, str, a);
                   fireInsertUpdate(new DefaultDocumentEvent(offs, 10, DocumentEvent.EventType.INSERT));
              catch(NumberFormatException e)
         public String getText()
         {     return String.valueOf(getValue());
         public String getText(int offset, int length) throws BadLocationException
         {     String s = String.valueOf(getValue());
              if (length > 0)
                   s = s.substring(offset, length);
              return s;
         public void getText(int offset, int length, Segment txt) throws BadLocationException
         {     //super.getText(offset, length, txt);
              char[] c = new char[10];
              String s = String.valueOf(getValue());
              s.getChars(offset, length, c, 0);
              txt = new Segment(c, 0, length);
         public String getValue()
         {     int i = settings.maxStudents;
              String s = String.valueOf(i);
              return s;          
         void setValue(int i)
         {     settings.maxStudents = i;
    }

    Hi!
    Thanks for your response. Unfortunately, based on your response, I guess that I must not have clearly communicated what I am trying to do.
    I am using both JTables and JTextFields, and would like to use them both in the same way.
    When using JTable, I extend an AbstractTableModel so that it refers to another data source (in a separate class), rather than one inside of the AbstractTableModel. Thus the getValueAt method, getColumnCount method, setValueAt method, . .. all call methods in another class. The details of that other class are irrelevant, but they could be accessing data from a database (via JDBC) or from other machines via some other communication mechanism.
    I would like to do exactly the same thing with a JTextField. I wish for the data to come from a class other than an object of type PlainDocument, or of any class that implements the Document interface. Instead, I would like to use a class that implements the Document interface to call my external class using methods similar to those found in AbstractTableModel.
    You may ask why I would like to to this. I have specific reasons here, but more generally this would be helpful when saving or retrieving parameters set and displayed in a JTextField to a database, or when sharing JTextField to multiple users located on different machines.
    As to whether this is real MVC or not, I think it is but it really doesn't matter.
    I know that I can accomplish what I want for the JTextField using listeners. However, I would like my code for the JTables to be similarly structured to that of the JTextField.
    Thanks/Phil Troy

  • JTable add a field JTextField

    hello
    I have a problem inserting into a table field JTextField
    I create my table in a window called Windows (class) following:
    Code:
    JScrollPane jScrollPane1 = new JScrollPane();
           String[] head = {"Nom", "Prènom", "Adresse", "Telephone", "ville ", "pays", "code Postal"};
           DefaultTableModel defaultModel = new DefaultTableModel(head, 0);
    JTable msgTable = new JTable(defaultModel);add to Class A:
    jScrollPane1.getViewport().add(msgTable);it works the table is displayed with the titles
    My first question is if I want to display in my table that the name and prémon
    What is the method?
    I create another class B intégtrant JTextField I wanted to write the fields (name, surname ,....) in JTextField with a button and add these fields to the table that is in Class A
    Following the code:
    JTextField name = new JTextField();
         JTextField addr = new JTextField();
    this.getContentPane().add(nameTField);
    this.getContentPane().add(addrTField);adding a button with an event insertion
    I tried addRow method and the other but I think the problem is the textField it must be changed into an object
    thank you for mounted a method to solve my problem

    addRow should work. But from the code you posted, we cannot see why it does not.
    Prepare an SSCCE and we can assist you. - And maybe, when writing the SSCCE, you discover the error yourself.

  • Can't Copy text unless console is opened before applet with JTextField

    If an applet uses JTextFields, it is impossible to copy text from the console to the clipboard (or anywhere else) if the console is opened after the applet.
    See http://demo.capmon.dk/~pvm/nocopy/nocopy.html for a working applet with source and class file to try it out on...
    So if something bad has happened, and there are hints in the console e.g. a stack trace, it all has to be retyped by hand, since all Copy or export is impossible...
    Does anyone know of a workaround for this? I'd like to be able to e.g. copy stack traces to bug reports.
    Try these test cases:
    * Close all browser windows. Open a browser and visit this page. After the page with this applet has loaded, then open the console with "Tools/Sun Java Console" (or "Tools/Web Development/Java Console" in Mozilla). Select some text in the console. There is no way to put this text on the clipboard; the "Copy" button doesn't work, and neither does CTRL+Insert, CTRL+C or anything else.
    * Close all browser windows. Open a browser window no some non-java page and then open the console with "Tools/Sun Java Console" (or "Tools/Web Development/Java Console" in Mozilla). Then visit this page. Select some text in the console. Now the "Copy" button does work, enabling "export" of e.g. stack traces to other applicaitons e.g. email.
    The difference is which is opened first: The console or the applet. If you look at the very rudimentary Java source code, it is the mere creation of a JTextField is what disables or breaks the Copy functionality.
    I've tried this on Windows XP with IE 6.0 and Mozilla 1.3 and they behave exactly the same. The JVM is Sun's 1.4.2 and I've tried 1.4.1_02 also with the same behavior. I've also tried javac from both 1.4.2 and 1.4.1_01

    hey .. this seems like a bug.. can you please file a bug at
    http://java.sun.com/webapps/bugreport
    thanks...

  • How do you add a new scene to beginning without disturbing movie with music and beat markers?

    How do you add a new portion to the beginning of your project without disturbing the rest of the project that already has perfectly place clips attached to beat markers with the music ?
    I forgot to add a tittle intro before the music starts with the attached pictures. When I try to add the whole project goes out of sync.
    I want to just add an intro without disturbing the entire project.
    Thanks

    Well, if you re-attach your background music under the first clip, the starting point will be at the start of that clip so I think it will still be in sync.  If not it's simply a matter of nudging the music track a bit along the timeline.  Comparing the audio waveforms of the two tracks should help with this.  When its right you can delete the track in the background music position.  Now you can add what you like before the first clip without affecting sync.
    Geoff.

  • Issue with JTextField Locking

    Hey All!
    I'm working on a database access project and have most things working pretty well, with one glaring exception.
    I've got a JInternalFrame form with 13 data fields to act as a front-end for a table in my database. Most of these data fields are JTextFields, some two are JRadioButtons, one is a JCheckbox and the last one is a JCombobox.
    To prevent accidental data editing, I lock the text fields down by setting JTextField.setEditable(false) and disable the other controls. I have the following method in my form:
    // Locks the form from allowing accidental edits.
        private void unlockForm( boolean unlock ) {
            this.isModifying = unlock;
            this.txtAniv.setEditable(unlock);
            this.txtApt.setEditable(unlock);
            this.txtBDate.setEditable(unlock);
            this.txtCity.setEditable(unlock);
            this.txtFName.setEditable(unlock);
            this.txtLName.setEditable(unlock);
            this.txtPhone.setEditable(unlock);
            this.txtStreet.setEditable(unlock);
            this.txtZip.setEditable(unlock);
            this.chkSearchable.setEnabled(unlock);
            this.optAM.setEnabled(unlock);
            this.optRA.setEnabled(unlock);
            // Set up the toolbar.
            this.setupToolbar();
        } // End of unlockForm() function.If I call this method from a toolbar button ActionPerformed() event and supply `true' as the parameter, it should set the editability of the text fields to true and also enable the other widgets. This seems to work pretty much as expected, except with my txtCity field, for some reason.
    When I click on my edit or add toolbar buttons, they call the unlockForm() method with the parameter set to `true'. However, when I attempt to change the data in the txtCity field, it acts as though it is still not editable. So, in an attempt to figure out what is going on here, I placed the following code in the FocusGained() event for the txtCity textbox:
            // DEBUGGING CODE:  Remove before release build!                      //
            // The following MessageBox is being displayed because I can not find //
            // the reason for the city field to not unlock and, yet, it will not  //
            // unlock for editing.  I need to figure this out!                    //
            MessageBox mb = new MessageBox();                                     //
            String msg = "The following are the settings of the city text field:";//
            msg += "\n-----------------------------------------------------\n";   //
            msg+ = "txtCity.getName() = "  +this.txtCity.getName();               //
            msg+ = "txtCity.getText() = "  +this.txtCity.getText();               //
            msg+ = "txtCity.isEditable() = "  +this.txtCity.isEditable();         //
            msg+ = "txtCity.isEnabled() = " + this.txtCity.isEnabled();           //
            mb.codeRequired(msg, this);                                           //
            ////////////////////////////////////////////////////////////////////////Now, when I click on the txtCity text field, I get this message box as expected, with one glaring problem. I get it more than once. Then, when I click on another control, I somehow go into an infinite loop of this message box being displayed and cannot get out of it. Here is my code for the FocusLost() event:
        private void txtCityFocusLost(java.awt.event.FocusEvent evt) {
            // Deselect the text.
            this.txtCity.select(0, 0);
            // Make sure that data was entered.
            if ( this.txtCity.getText() == null ||
                    this.txtCity.getText().length() == 0 ||
                    this.txtCity.getText().equals("") ) {
                this.txtCity.setBackground(errBG);
                this.txtCity.setForeground(errFG);
                this.txtCity.setFont(errFont);
                this.getToolkit().beep();
            } else {
                this.txtCity.setBackground(stdBG);
                this.txtCity.setFont(stdFont);
                this.txtCity.setForeground(stdFG);
                // Make sure the data was stored.
                this.entry.setCity(this.txtCity.getText());
        }Does anyone have any ideas as to what is going on? Maybe you could point me to a web site or book that actually has this problem and shows how to resolve it. I am at a complete loss as to what's happening, especially since I don't have any code in my FocusLost() event that points to my FocusGained() event. Any help that you can provide will be greatly appreciated.
    If it would help to see what the form looks like, you can view it here:
    http://pekinsoft.homelinux.org/CongregationManager.png
    Thank you for any and all help you may provide.
    Cheers,
    Sean C.
    PekinSOFT Systems
    Edited by: PekinSOFT.Systems on Oct 1, 2009 2:34 PM

    warnerja and camickr:
    I think you all hit it on the nose. My problem was that NetBeans would not go into debug mode due to some vague NullPointerException. However, I deleted my NetBeans user directory and, voila, I can debug again.
    So, when I debugged the code (without my crappy work-around attempt), I found that for some reason, when I click on or tab into the JTextField in question, it actually does go through the FocusGained event more than once, which I still cannot figure out, even going into the source for the Java APIs that get called. It's really weird and the strangest thing of all is that it is now, all of a sudden, working as expected. So, even though I have no clue what caused the issue to begin with, it seems to have cleared up.
    In reference to the post about the SSCCE, I tried to post one, but when I created it, it worked as expected and so was no help in showing my problem. However, when I created the SSCCE, I had already taken the action on my NetBeans user directory, so I'm thinking that something was broken there. Hazards of verifying plugins, I guess.
    Anyway, thank you all very much for your (unneeded, as it turns out) help to my (not actually a) Java problem. Next time I get some strange behavior like this, I think that I'll check my IDE first. ;-)
    Cheers,
    Sean C.
    PekinSOFT Systems

  • JTable Combobox editor with PrppertychangeListener

    Hello,
    I need a help from experts.
    I have a JTable. In the java table i need to have a ComboBox editor for example on the second column. And when i am changing value in the combobox i need to to do some calculations in JTable object.
    To setup a PropertyChangeListener on combo object is not what i want, because i can not make calcultions inside JTable.
    I need ComboBox based editor for JTable with property change listener.
    Can anybody point me to some example o sugest something?
    Thanks a lot

    Sollution
    package kelias.table.editor;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JTable;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.Component;
    import kelias.ComboBox.MyDBComboBox;
    Implements a cell editor that uses a formatted text field
    to edit Integer values.
    public class CarJobEditor extends DefaultCellEditor implements ItemListener
    MyDBComboBox comboJobs;
    //Darbo kiekis
    String jobQuantity=new String();
    //Lentel�
    JTable tableTmp;
    //Einamoji eilut�
    int rowTmp;
    int jobQColNumber;
    int resultColIndex;
    public CarJobEditor(int jobQColNumber,int resultColIndex)
    super(new MyDBComboBox());
    this.jobQColNumber=jobQColNumber;
    this.resultColIndex=resultColIndex;
    comboJobs = (MyDBComboBox) getComponent();
    comboJobs.loadData(kelias.db.DBStrings.selectJobsForCombo());
    comboJobs.addItemListener(this);
    //Override to invoke setValue on the formatted text field.
    public Component getTableCellEditorComponent(JTable table,Object value, boolean isSelected,int row, int column)
         jobQuantity=(String)table.getValueAt(row,jobQColNumber);
         this.tableTmp=table;
         this.rowTmp=row;
    MyDBComboBox tmp = (MyDBComboBox)super.getTableCellEditorComponent(table, value, isSelected, row, column);
    tmp.setSelectedItem(value);
    return tmp;
    public void itemStateChanged(ItemEvent event)
         if(event.getStateChange() == ItemEvent.SELECTED)
              if (!this.jobQuantity.equals(""))
                   float price=kelias.db.DBGetData.selectJobPricePM(comboJobs.getSelectedItem());
                   float quantity=Float.parseFloat((String)jobQuantity);
                   float f = (float) (Math.round(price*quantity*100.0f)/100.0f);
                   tableTmp.setValueAt(f,rowTmp,resultColIndex);
    }

  • JTable selection problem with jdk1.5.0_05

    Today I tried the new jdk1.5.0_05 release and noticed with a JTable I can only select a single column and row with the mouse. With jdk1.5.0_05 I could select multiple cols and rows with the mouse. I looking at the listselectionmodel for the jtable i see it is set to mulitple. Is this a bug in the new java 1.5 release?

    Yeah, the .jar files are definitely there and the
    small class I just wrote is in the Classes directory.Yes, but you're calling javac.exe, not some jars. Did you check that javac.exe is there? Stupid question, yes, but I've seen it all...
    I changed the path in Control Panel -> System ->
    Advanced -> Environment Variables. I've also beendoing this is the command prompt:
    set
    CLASSPATH=%CLASSPATH%;C:\Java\jdk1.5.0\bin;C:\Java\Cla
    ssesNo need to add the /bin directory to the classpath, there are no classes in it...

  • A serious problem with JTable to update with new data.

    I am customizing a JTable. In the table 3 rows and row wise same data presents. After every 30 sec table will be update with new data. But a exception is coming like: ArrayIndexOutofBound 4>=0. Exception is not coming so frequently some time it comes within 1 min or after 1 hour of program running and each time *4>=0* is varies with different number.
    Here is the model i am using and to update table i am calling setTableData( ) with updated vector as a argument.
    public class MyModel extends AbstractTableModel {
              protected Vector m_vector;          
              public MyModel(Vector m_vector) {     this.m_vector = m_vector;     }
              public int getColumnCount() {          
                   return m_vector==null ? 0 : m_vector.size();           
              public int getRowCount() {     return 3;          }
              public String getColumnName(int col) {     return null;     }
              public Object getValueAt(int row, int col) {
                       if (col < 0 || col>=getColumnCount())
                      return null;
                  try{
                  MyData column = (MyData)m_vector.elementAt(col);               
                  switch (row) {
                      case 0: return column.gate;
                      case 1: return column.time;
                      case 2: return column.status;            
                  }}catch(Exception e){
                        System.out.println("Error is here");
                        e.printStackTrace();
                  return null;               
              public Class getColumnClass(int c) {return getValueAt(0, c).getClass();     }
              public boolean isCellEditable(int row, int col) {
                   if (row == 1) { return false; } else { return true; }
              public void setTableData( Vector mData)
                         this.m_vector = new Vector(mData);                    
                         fireTableStructureChanged();
         }Please help me out.

    This is the exception:
    java.lang.ArrayIndexOutOfBoundsException: 4 >= 3
         at java.util.Vector.elementAt(Vector.java:431)
         at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:277)
         at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1047)
         at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
         at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
         at javax.swing.JComponent.paintComponent(JComponent.java:541)
         at javax.swing.JComponent.paint(JComponent.java:808)
         at javax.swing.JComponent.paintChildren(JComponent.java:647)
         at javax.swing.JComponent.paint(JComponent.java:817)
         at javax.swing.JViewport.paint(JViewport.java:722)
         at javax.swing.JComponent.paintChildren(JComponent.java:647)
         at javax.swing.JComponent.paint(JComponent.java:817)
         at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
         at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
         at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
         at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
         at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)and Column may increase/decrease depending upon data retrieved.

  • How to create a password with JTextField

    Hi, I need to create a password field on the JTabbedPane. I can create a TextField and setEchoChar to make it a password field. However it is not working well with the rest of the JComponents. Can I do this on a JTextField? I could not find the functionality.
    Thanks for the help!
    -Joanne

    use JPasswordField instead

Maybe you are looking for