Results 1 to 2 of 2
  1. #1
    msambasiva is offline Member
    Join Date
    Jun 2013
    Posts
    18
    Rep Power
    0

    Default Issue - JComponenets are showing as small icons on JXTable population

    Hi,

    User can select required options from JList and JTree and then click on JButton (Fetch). JXTable should display with rows according to user selection from JList and JTree.
    Initially, it is displaying the table as per expectation (Screenshot1). But if we try to expand the window or click on table, the JComponents are getting disturbed as shown in Screenshot2.

    It would be really great help, if you can suggest on this.

    Following is the code used to display layout and Table creation process.

    XML Code:
        public SOS() throws SQLException {
            //EHDD Tabbed Pane
    
            //JList with Checkbox
            ehddOwmerslist = new JList((createOwnersListData()).toArray());
            ehddOwmerslist.setCellRenderer(new CheckListRenderer());
            ehddOwmerslist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            ehddOwmerslist.setBorder(new EmptyBorder(0, 4, 0, 0));
            ehddOwmerslist.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        int index = ehddOwmerslist.locationToIndex(e.getPoint());
                        CheckableItem item =
                            (CheckableItem)ehddOwmerslist.getModel().getElementAt(index);
                        item.setSelected(!item.isSelected());
                        Rectangle rect =
                            ehddOwmerslist.getCellBounds(index, index);
                        ehddOwmerslist.repaint(rect);
                    }
                });
            JScrollPane sp = new JScrollPane(ehddOwmerslist);
    
            //JTree with checkbox
            DefaultMutableTreeNode root = createFirstLevel();
            final DefaultTreeModel model = new DefaultTreeModel(root);
            ehddTree = new JTree(root);
            QuestionCellRenderer renderer = new QuestionCellRenderer();
            ehddTree.setCellRenderer(renderer);
            QuestionCellEditor editor = new QuestionCellEditor();
            ehddTree.setCellEditor(editor);
            ehddTree.setEditable(true);
            ehddTree.addTreeWillExpandListener(this);
            ehddTree.setShowsRootHandles(true);
            ehddTree.setModel(model);
            ehddTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
            JScrollPane scroll = new JScrollPane(ehddTree);
            scroll.setPreferredSize(new Dimension(200, 200));
    
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5, 5, 5, 5);
            //gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            //gbc.fill  = GridBagConstraints.NONE;
    
            //gbc.fill = GridBagConstraints.VERTICAL;
            gbc.gridx = 0;
            gbc.gridy = 0;
            firstPanel.add(new JLabel("EHDD Document Owners"), gbc);
    
            gbc.gridx = 1;
            gbc.gridy = 0;
            firstPanel.add(new JLabel("EHDD Product Activity Task Tree"), gbc);
    
            gbc.weightx = 1;
            gbc.weighty = 1;
            gbc.gridx = 0;
            gbc.gridy = 1;
            firstPanel.add(sp, gbc);
    
            gbc.gridx = 1;
            gbc.gridy = 1;
            firstPanel.add(scroll, gbc);
    
            gbc.weightx = 0;
            gbc.weighty = 0;
            gbc.gridheight = 1;
    
            //gbc.fill =     GridBagConstraints.HORIZONTAL;
            //gbc.gridheight = 2;
            gbc.gridheight = 1;
            gbc.gridx = 0;
            gbc.gridy = 22;
            firstPanel.add(new JButton("Saved Searches"), gbc);
    
            gbc.gridx = 1;
            gbc.gridy = 22;
            firstPanel.add(new JButton("Save this Search"), gbc);
    
            gbc.gridx = 0;
            gbc.gridy = 25;
            JButton fetchButton = new JButton("Fetch");
            firstPanel.add(fetchButton, gbc);
            fetchButton.addActionListener(new ActionListener() {
    
                    public void actionPerformed(ActionEvent e) {
                        //Execute when button is pressed
                        System.out.println("You clicked the fetch button");
                        try {
                            fetchTopics();
                        } catch (SQLException f) {
                        }
                    }
                });
            gbc.gridx = 1;
            gbc.gridy = 25;
            firstPanel.add(new JButton("Fetch Favorite"), gbc);
            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            gbc.gridwidth = 4;
            //gbc.gridheight = 10;
            gbc.gridx = 0;
            gbc.gridy = 26;
            gbc.fill = GridBagConstraints.HORIZONTAL;
    
            firstPanel.add(tableScrollPane, gbc);
    
    
            tabbedPane.add("EHDD", firstPanel);
            //tabbedPane.add(secondPanel,BorderLayout.NORTH);
    
    
            //NEH Tabbed Pane
            tabbedPane.add("NEH", secondPanel);
            add(tabbedPane);
    
    
        }
    
        public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException {
    
            ResultSetMetaData metaData = rs.getMetaData();
    
            // names of columns
            Vector<String> columnNames = new Vector<String>();
            int columnCount = metaData.getColumnCount();
            for (int column = 1; column <= columnCount; column++) {
                columnNames.add(metaData.getColumnName(column));
            }
    
            // data of the table
            Vector<Vector<Object>> data = new Vector<Vector<Object>>();
            while (rs.next()) {
                Vector<Object> vector = new Vector<Object>();
                for (int columnIndex = 1; columnIndex <= columnCount;
                     columnIndex++) {
                    vector.add(rs.getObject(columnIndex));
                }
                data.add(vector);
            }
    
            return new DefaultTableModel(data, columnNames);
    
        }
    
        public void fetchTopics() throws SQLException {
    
            //TreeModel tmodel = ehddTree.getModel();
            traverse(ehddTree);
            ListModel lModel = ehddOwmerslist.getModel();
            int listSize = lModel.getSize();
            for (int i = 0; i < listSize; i++) {
                CheckableItem checkableItem =
                    (CheckableItem)lModel.getElementAt(i);
                if (checkableItem.isSelected() == true)
                    ownerSelectionList.add(checkableItem);
            }
            Iterator ownerSelectionListItr = ownerSelectionList.iterator();
            String ownerSelectionStr = "";
            while (ownerSelectionListItr.hasNext()) {
                CheckableItem checkableItem =
                    (CheckableItem)ownerSelectionListItr.next();
                ownerSelectionStr =
                        ownerSelectionStr + checkableItem.getId() + ",";
            }
    
    
            Iterator prodFamilySelectionNodeListItr =
                prodFamilySelectionNodeList.iterator();
            String prodFamilySelectionStr = "";
            while (prodFamilySelectionNodeListItr.hasNext()) {
                //TrueFalseTreeNodeData checkableItem = (TrueFalseTreeNodeData)prodFamilySelectionNodeListItr.next();
                prodFamilySelectionStr =
                        prodFamilySelectionStr + prodFamilySelectionNodeListItr.next() +
                        ",";
            }
            System.out.println("prodFamilySelectionStr" + prodFamilySelectionStr);
    
    
            Iterator prodSelectionNodeListItr = prodSelectionNodeList.iterator();
            String prodSelectionStr = "";
            while (prodSelectionNodeListItr.hasNext()) {
                prodSelectionStr =
                        prodSelectionStr + prodSelectionNodeListItr.next() + ",";
            }
            System.out.println("prodSelectionStr" + prodSelectionStr);
    
            Iterator activitySelectionNodeListItr =
                activitySelectionNodeList.iterator();
            String activitySelectionNodeStr = "";
            while (activitySelectionNodeListItr.hasNext()) {
                //TrueFalseTreeNodeData checkableItem = (TrueFalseTreeNodeData)activitySelectionNodeListItr.next();
                activitySelectionNodeStr =
                        activitySelectionNodeStr + activitySelectionNodeListItr.next() +
                        ",";
            }
            System.out.println("activitySelectionNodeStr" +
                               activitySelectionNodeStr);
    
            String fetchSql =
                "SELECT * FROM MY_TABLE";
    
            if (prodFamilySelectionStr != null &&
                prodFamilySelectionStr.length() > 0) {
                prodFamilySelectionStr =
                        prodFamilySelectionStr.substring(0, prodFamilySelectionStr.length() -
                                                         1);
                fetchSql =
                        fetchSql + "   and fam.PRODUCT_FAMILY_ID in (" + prodFamilySelectionStr +
                        ")";
            }
    
            if (prodSelectionStr != null && prodSelectionStr.length() > 0) {
                prodSelectionStr =
                        prodSelectionStr.substring(0, prodSelectionStr.length() -
                                                   1);
                fetchSql =
                        fetchSql + "   and prod.PRODUCT_ID in (" + prodSelectionStr +
                        ")";
            }
            if (activitySelectionNodeStr != null &&
                activitySelectionNodeStr.length() > 0) {
                activitySelectionNodeStr =
                        activitySelectionNodeStr.substring(0, activitySelectionNodeStr.length() -
                                                           1);
                fetchSql =
                        fetchSql + "   and a.ACTIVITY_ID in (" + activitySelectionNodeStr +
                        ")";
            }
            if (ownerSelectionStr != null && ownerSelectionStr.length() > 0) {
                ownerSelectionStr =
                        ownerSelectionStr.substring(0, ownerSelectionStr.length() -
                                                    1);
                fetchSql =
                        fetchSql + "   and AUTHOR_ID in (" + ownerSelectionStr + ")";
            }
            //        fetchSql = fetchSql + "   and AUTHOR_ID in (9)";
            System.out.println("FETCH SQL" + fetchSql);
            dbh handle = new dbh();
            try {
                handle.open(dbusername, dbpassword, url, sidIn, "true");
                connection = handle.getConnection();
            } catch (Exception e) {
                System.out.println("Exception caught:\n" +
                        e.getMessage());
            }
            stmt = connection.createStatement();
            ResultSet rs = null;
    
            rs = stmt.executeQuery(fetchSql);
    
            topicsTable.setModel(buildTableModel(rs));
            ((DefaultTableModel)topicsTable.getModel()).fireTableDataChanged();
            topicsTable.setFillsViewportHeight(true);
            topicsTable.setColumnControlVisible(true);
            topicsTable.setHorizontalScrollEnabled(true);
            firstPanel.repaint();
        }
    Thanks in advance,
    Samba
    Attached Thumbnails Attached Thumbnails Issue - JComponenets are showing as small icons on JXTable population-screenshot1.png   Issue - JComponenets are showing as small icons on JXTable population-screenshot2.png  

  2. #2
    msambasiva is offline Member
    Join Date
    Jun 2013
    Posts
    18
    Rep Power
    0

    Default Re: Issue - JComponenets are showing as small icons on JXTable population

    Iam able to fix the issue using

    tableScrollPane.setPreferredSize(new Dimension(200, 200));

    Thanks,
    Samba.

    Quote Originally Posted by msambasiva View Post
    Hi,

    User can select required options from JList and JTree and then click on JButton (Fetch). JXTable should display with rows according to user selection from JList and JTree.
    Initially, it is displaying the table as per expectation (Screenshot1). But if we try to expand the window or click on table, the JComponents are getting disturbed as shown in Screenshot2.

    It would be really great help, if you can suggest on this.

    Following is the code used to display layout and Table creation process.

    XML Code:
        public SOS() throws SQLException {
            //EHDD Tabbed Pane
    
            //JList with Checkbox
            ehddOwmerslist = new JList((createOwnersListData()).toArray());
            ehddOwmerslist.setCellRenderer(new CheckListRenderer());
            ehddOwmerslist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            ehddOwmerslist.setBorder(new EmptyBorder(0, 4, 0, 0));
            ehddOwmerslist.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        int index = ehddOwmerslist.locationToIndex(e.getPoint());
                        CheckableItem item =
                            (CheckableItem)ehddOwmerslist.getModel().getElementAt(index);
                        item.setSelected(!item.isSelected());
                        Rectangle rect =
                            ehddOwmerslist.getCellBounds(index, index);
                        ehddOwmerslist.repaint(rect);
                    }
                });
            JScrollPane sp = new JScrollPane(ehddOwmerslist);
    
            //JTree with checkbox
            DefaultMutableTreeNode root = createFirstLevel();
            final DefaultTreeModel model = new DefaultTreeModel(root);
            ehddTree = new JTree(root);
            QuestionCellRenderer renderer = new QuestionCellRenderer();
            ehddTree.setCellRenderer(renderer);
            QuestionCellEditor editor = new QuestionCellEditor();
            ehddTree.setCellEditor(editor);
            ehddTree.setEditable(true);
            ehddTree.addTreeWillExpandListener(this);
            ehddTree.setShowsRootHandles(true);
            ehddTree.setModel(model);
            ehddTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
            JScrollPane scroll = new JScrollPane(ehddTree);
            scroll.setPreferredSize(new Dimension(200, 200));
    
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5, 5, 5, 5);
            //gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            //gbc.fill  = GridBagConstraints.NONE;
    
            //gbc.fill = GridBagConstraints.VERTICAL;
            gbc.gridx = 0;
            gbc.gridy = 0;
            firstPanel.add(new JLabel("EHDD Document Owners"), gbc);
    
            gbc.gridx = 1;
            gbc.gridy = 0;
            firstPanel.add(new JLabel("EHDD Product Activity Task Tree"), gbc);
    
            gbc.weightx = 1;
            gbc.weighty = 1;
            gbc.gridx = 0;
            gbc.gridy = 1;
            firstPanel.add(sp, gbc);
    
            gbc.gridx = 1;
            gbc.gridy = 1;
            firstPanel.add(scroll, gbc);
    
            gbc.weightx = 0;
            gbc.weighty = 0;
            gbc.gridheight = 1;
    
            //gbc.fill =     GridBagConstraints.HORIZONTAL;
            //gbc.gridheight = 2;
            gbc.gridheight = 1;
            gbc.gridx = 0;
            gbc.gridy = 22;
            firstPanel.add(new JButton("Saved Searches"), gbc);
    
            gbc.gridx = 1;
            gbc.gridy = 22;
            firstPanel.add(new JButton("Save this Search"), gbc);
    
            gbc.gridx = 0;
            gbc.gridy = 25;
            JButton fetchButton = new JButton("Fetch");
            firstPanel.add(fetchButton, gbc);
            fetchButton.addActionListener(new ActionListener() {
    
                    public void actionPerformed(ActionEvent e) {
                        //Execute when button is pressed
                        System.out.println("You clicked the fetch button");
                        try {
                            fetchTopics();
                        } catch (SQLException f) {
                        }
                    }
                });
            gbc.gridx = 1;
            gbc.gridy = 25;
            firstPanel.add(new JButton("Fetch Favorite"), gbc);
            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            gbc.gridwidth = 4;
            //gbc.gridheight = 10;
            gbc.gridx = 0;
            gbc.gridy = 26;
            gbc.fill = GridBagConstraints.HORIZONTAL;
    
            firstPanel.add(tableScrollPane, gbc);
    
    
            tabbedPane.add("EHDD", firstPanel);
            //tabbedPane.add(secondPanel,BorderLayout.NORTH);
    
    
            //NEH Tabbed Pane
            tabbedPane.add("NEH", secondPanel);
            add(tabbedPane);
    
    
        }
    
        public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException {
    
            ResultSetMetaData metaData = rs.getMetaData();
    
            // names of columns
            Vector<String> columnNames = new Vector<String>();
            int columnCount = metaData.getColumnCount();
            for (int column = 1; column <= columnCount; column++) {
                columnNames.add(metaData.getColumnName(column));
            }
    
            // data of the table
            Vector<Vector<Object>> data = new Vector<Vector<Object>>();
            while (rs.next()) {
                Vector<Object> vector = new Vector<Object>();
                for (int columnIndex = 1; columnIndex <= columnCount;
                     columnIndex++) {
                    vector.add(rs.getObject(columnIndex));
                }
                data.add(vector);
            }
    
            return new DefaultTableModel(data, columnNames);
    
        }
    
        public void fetchTopics() throws SQLException {
    
            //TreeModel tmodel = ehddTree.getModel();
            traverse(ehddTree);
            ListModel lModel = ehddOwmerslist.getModel();
            int listSize = lModel.getSize();
            for (int i = 0; i < listSize; i++) {
                CheckableItem checkableItem =
                    (CheckableItem)lModel.getElementAt(i);
                if (checkableItem.isSelected() == true)
                    ownerSelectionList.add(checkableItem);
            }
            Iterator ownerSelectionListItr = ownerSelectionList.iterator();
            String ownerSelectionStr = "";
            while (ownerSelectionListItr.hasNext()) {
                CheckableItem checkableItem =
                    (CheckableItem)ownerSelectionListItr.next();
                ownerSelectionStr =
                        ownerSelectionStr + checkableItem.getId() + ",";
            }
    
    
            Iterator prodFamilySelectionNodeListItr =
                prodFamilySelectionNodeList.iterator();
            String prodFamilySelectionStr = "";
            while (prodFamilySelectionNodeListItr.hasNext()) {
                //TrueFalseTreeNodeData checkableItem = (TrueFalseTreeNodeData)prodFamilySelectionNodeListItr.next();
                prodFamilySelectionStr =
                        prodFamilySelectionStr + prodFamilySelectionNodeListItr.next() +
                        ",";
            }
            System.out.println("prodFamilySelectionStr" + prodFamilySelectionStr);
    
    
            Iterator prodSelectionNodeListItr = prodSelectionNodeList.iterator();
            String prodSelectionStr = "";
            while (prodSelectionNodeListItr.hasNext()) {
                prodSelectionStr =
                        prodSelectionStr + prodSelectionNodeListItr.next() + ",";
            }
            System.out.println("prodSelectionStr" + prodSelectionStr);
    
            Iterator activitySelectionNodeListItr =
                activitySelectionNodeList.iterator();
            String activitySelectionNodeStr = "";
            while (activitySelectionNodeListItr.hasNext()) {
                //TrueFalseTreeNodeData checkableItem = (TrueFalseTreeNodeData)activitySelectionNodeListItr.next();
                activitySelectionNodeStr =
                        activitySelectionNodeStr + activitySelectionNodeListItr.next() +
                        ",";
            }
            System.out.println("activitySelectionNodeStr" +
                               activitySelectionNodeStr);
    
            String fetchSql =
                "SELECT * FROM MY_TABLE";
    
            if (prodFamilySelectionStr != null &&
                prodFamilySelectionStr.length() > 0) {
                prodFamilySelectionStr =
                        prodFamilySelectionStr.substring(0, prodFamilySelectionStr.length() -
                                                         1);
                fetchSql =
                        fetchSql + "   and fam.PRODUCT_FAMILY_ID in (" + prodFamilySelectionStr +
                        ")";
            }
    
            if (prodSelectionStr != null && prodSelectionStr.length() > 0) {
                prodSelectionStr =
                        prodSelectionStr.substring(0, prodSelectionStr.length() -
                                                   1);
                fetchSql =
                        fetchSql + "   and prod.PRODUCT_ID in (" + prodSelectionStr +
                        ")";
            }
            if (activitySelectionNodeStr != null &&
                activitySelectionNodeStr.length() > 0) {
                activitySelectionNodeStr =
                        activitySelectionNodeStr.substring(0, activitySelectionNodeStr.length() -
                                                           1);
                fetchSql =
                        fetchSql + "   and a.ACTIVITY_ID in (" + activitySelectionNodeStr +
                        ")";
            }
            if (ownerSelectionStr != null && ownerSelectionStr.length() > 0) {
                ownerSelectionStr =
                        ownerSelectionStr.substring(0, ownerSelectionStr.length() -
                                                    1);
                fetchSql =
                        fetchSql + "   and AUTHOR_ID in (" + ownerSelectionStr + ")";
            }
            //        fetchSql = fetchSql + "   and AUTHOR_ID in (9)";
            System.out.println("FETCH SQL" + fetchSql);
            dbh handle = new dbh();
            try {
                handle.open(dbusername, dbpassword, url, sidIn, "true");
                connection = handle.getConnection();
            } catch (Exception e) {
                System.out.println("Exception caught:\n" +
                        e.getMessage());
            }
            stmt = connection.createStatement();
            ResultSet rs = null;
    
            rs = stmt.executeQuery(fetchSql);
    
            topicsTable.setModel(buildTableModel(rs));
            ((DefaultTableModel)topicsTable.getModel()).fireTableDataChanged();
            topicsTable.setFillsViewportHeight(true);
            topicsTable.setColumnControlVisible(true);
            topicsTable.setHorizontalScrollEnabled(true);
            firstPanel.repaint();
        }
    Thanks in advance,
    Samba

Similar Threads

  1. Population growth!
    By reginal in forum New To Java
    Replies: 2
    Last Post: 01-29-2013, 06:36 PM
  2. Java jar files not showing icons on taskbar??!
    By srisar in forum Forum Lobby
    Replies: 0
    Last Post: 12-25-2009, 02:03 PM
  3. a small issue "I THINK"
    By Ozmosis in forum Networking
    Replies: 4
    Last Post: 10-29-2009, 09:31 PM
  4. Combo Box Population
    By barusk in forum Java Applets
    Replies: 1
    Last Post: 03-20-2009, 02:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •