Home Answers Viewqa Java-Beginners JTABLE SCROLL PANE

 
 


DEEpanshu
JTABLE SCROLL PANE
0 Answer(s)      7 months ago
Posted in : Java Beginners

The scrollpane for a image in Jtable is only showing but not working ....here is the code i am doing please suggest something...

import java.awt.Component; import java.io.FileReader; import java.util.StringTokenizer; import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer;

public class TableImage extends javax.swing.JFrame {

/**
 * Creates new form TableImage
 */
public TableImage() {
    initComponents();
}                        
private void initComponents() {

    jFileChooser1 = new javax.swing.JFileChooser();
    jButton1 = new javax.swing.JButton();
    jTextField1 = new javax.swing.JTextField();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTable1 = new javax.swing.JTable();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jButton1.setText("BROWSE");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jTextField1.setText("jTextField1");

    jTable1.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {
            {null, null, null},
            {null, null, null},
            {null, null, null}
        },
        new String [] {
            "NAME", "CITY", "Title 3"
        }
    ));
    jTable1.setRowHeight(150);
    jScrollPane1.setViewportView(jTable1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(128, 128, 128)
            .addComponent(jButton1)
            .addGap(181, 181, 181))
        .addGroup(layout.createSequentialGroup()
            .addGap(21, 21, 21)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE)
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(34, 34, 34)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    pack();
}// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

try{
jFileChooser1.showOpenDialog(this);

       String path=jFileChooser1.getSelectedFile().getAbsolutePath();
       //txtname.setText(path);
       FileReader file=new FileReader(path);
      String header[]={"NAME","Address","Contact","Email","IMAGE"};
       Object[][] data=new Object[50][5];
       String record="";
        for(int i=file.read();i!=-1;i=file.read())
            record+= (char)i;
         StringTokenizer stt=new StringTokenizer(record,"\n");
         for(int i=0;stt.hasMoreTokens();i++){
          StringTokenizer st=new StringTokenizer(stt.nextToken(),"\t");
         jTable1.setValueAt(st.nextToken(), i, 0);
          jTable1.setValueAt(st.nextToken(), i, 1);
          // jTable1.setValueAt(st.nextToken(), i, 2);

   jTable1.setValueAt(new ImageIcon(st.nextToken().trim()),i,2);
   jTable1.getColumnModel().getColumn(2).setCellRenderer(new TableCellRender());
    }}
    catch(Exception e)
    {
         JOptionPane.showMessageDialog(null,e,"file not Saved",JOptionPane.ERROR_MESSAGE);
    }
                       // TODO add your handling code here:
}                                        

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /*
     * Set the Nimbus look and feel
     */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /*
     * 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(TableImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(TableImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(TableImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(TableImage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /*
     * Create and display the form
     */
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new TableImage().setVisible(true);
        }
    });
}
// Variables declaration - do not modify                     
private javax.swing.JButton jButton1;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

class TableCellRender extends DefaultTableCellRenderer {
JLabel lbl=new JLabel(); JLabel lbl1=new JLabel(); private Icon Imageicon; @Override public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasfocus,int row,int col) { lbl.setIcon((ImageIcon)value); JScrollPane pane =new JScrollPane(lbl); return pane; } } }

View Answers









Related Pages:
JTABLE SCROLL PANE
JTABLE SCROLL PANE  The scrollpane for a image in Jtable is only showing but not working ....here is the code i am doing please suggest something... import java.awt.Component; import java.io.FileReader; import
JTABLE SCROLL PANE
JTABLE SCROLL PANE  The scrollpane for a image in Jtable is only showing but not working ....here is the code i am doing please suggest something... import java.awt.Component; import java.io.FileReader; import
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane(table); frame.add(pane); frame.setVisible(true... to rewrite my program so you can scroll and data exists in more than one line
Java scroll pane-java GUI
Java scroll pane-java GUI  Dear friends.. Very Good morning. I have a doubt in my gui application. Take ex:- My gui application has 1 Jscrollpane of height 600 and width 400. normally it is showing 200 height and 400 width
Create a Scroll Pane Container in Java
Create a Scroll Pane Container in Java   ... to create a scroll pane container in Java Swing. When you simply create a Text Area... for the result of the given program: This program shows a scroll pane
problem Scrolling jTable in scrollpane
problem Scrolling jTable in scrollpane  hi i get into a problem of scrolling jtable in scrollpane.Only horizontal scroll is working, vertical scroll...)); tableModel =new DefaultTableModel(rowdata, colname); table = new JTable
problem Scrolling jTable in scrollpane
problem Scrolling jTable in scrollpane  hi i get into a problem of scrolling jtable in scrollpane.Only horizontal scroll is working, vertical scroll...)); tableModel =new DefaultTableModel(rowdata, colname); table = new JTable
java gui-with jscroll pane
...but it is not in that screen/window.If he need to see that part he should scroll
java gui-with jscroll pane
...but it is not in that screen/window.If he need to see that part he should scroll
Creating a Scrollable JTable
Creating a Scrollable JTable : Swing Tutorials ... section, you will learn how to create a scrollable JTable component. When any table has large volume of data, the use of scrollbar is applied in the JTable
jtable with table headers - Swing AWT
jtable with table headers  give me java code to create jtable with table headers and by which i can scroll jtable and can retrieve height and width of the table
JTable - Swing AWT
JTable  Hi Deepak, i want to display the Jtable data... how could i show jtable data on the console. Thanks, Prashant   Hi...*; public class JTableToConsole extends JFrame { public Object GetData(JTable
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
the drawing area in a scroll pane. JScrollPane scroller = new... the scroll pane. */ public class DrawingPane extends JPanel...) { drawingPane.setPreferredSize(area); //Let the scroll pane know to update
Scroll ImagesUIScrollView
Scroll ImagesUIScrollView  Hi, Can anyone please suggest me how to scroll images in UIScrollView in iPad? THanks
Connecting JTable to database - JDBC
Connecting JTable to database  Hi.. I am doing a project on Project... to store this JTable content in my database table.. This is a very important... InsertJTableDatabase{ JTable table; JButton button; public static void main(String
update a JTable - Java Beginners
update a JTable   how to update a JTable with Mysql data through user... in an updatable JTable You would create the table as follows: conn = getConnection(); stat = conn.createStatement(ResultSet.TYPE_SCROLL
problem scrolling jtable
--) { tableModel.removeRow(i); } pane.remove(table); panel.remove(pane...;}}; table = new JTable(tableModel...(); pane = new JScrollPane(table); pane.setAutoscrolls(true
Not able to display jtable at runtime
Not able to display jtable at runtime  Hello, can anyone please help...[][] taskcells; JTable ttable; public void BuildTable() { Statement st; ResultSet rs...:dsndbPMA","",""); st=conn.createStatement(ResultSet.TYPE_SCROLL
update a JTable - Java Beginners
update a JTable   i have tried your advice as how to update a JTable... main(String args[]) { JTable table; Connection con = null... = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE
Scroll in JPanel
Scroll in JPanel  Hello sir,  Hi Friend, You can use the following code: import java.awt.*; import javax.swing.*; class scroll { public static void main(String[] args) { Frame f = new Frame ("Demo"); JPanel p = new
search filter and JTable
my question is: how can i make search data in JTable of java? i wan to search records in table or textfield but the data display in JTable. Note: i dont...","Contact No","Email"}; JTable table=new JTable(data,labels
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
CONVERT JTable DATA TO PDF FILE
(data, col); table = new JTable(model); JScrollPane pane = new JScrollPane(table...CONVERT JTable DATA TO PDF FILE  HOW TO CONVERT JTable DATA TO .PDF... the jtable data from the jframe and stored the data into the pdf file in the form
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
sum of all values in a column of jtable
, is there a code to display the sum of all values in a column of a jtable namely CARTtbl... or deleted.   Here is an example of jtable that sums up the values of two... JTableAction { JTable table; public static void main(String[] args) { new
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
Excel Freeze Pane Feature
Excel Freeze Pane Feature In this section, you will learn about freezing row of excel document using Apache POI library. Sometimes when you scroll down too... which cell belongs to which heading. The solution of this problem is Freeze Pane
JTable Cell Validation? - Swing AWT
JTable Cell Validation?  hi there please i want a simple example of JTable with 3 columns Name,Number,Price and the first columns is string... javax.swing.JList; public class JTableValidation { static JTable table; static
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
Shading Columns in JTable
Shading Columns in JTable     ...; the rows in JTable. So, you are now capable for setting the shading the column in JTable.  In JTable component the shading columns are the simplest way
Moving a Column in JTable
Moving a Column in JTable       This section describes, how to move a column in JTable... position to another specified position in JTable via using the moveColumn() method
Setting Cell Values in JTable
Setting Cell Values in JTable     ... values in JTable component. For this you must have the some previous knowledge about JTable. A cell is known as the format of  a row and a column in 
Packing a JTable Component
Packing a JTable Component     ...; a JTable by adjusting it in the center.  Description of program: This program helps you in packing a JTable component. For this you will need a JTable having
javascript set scroll height
javascript set scroll height  How to set scroll height in JavaScript?   CSS Scroll Method div { width:150px; height:150px; overflow:scroll; } JavaScript ScrollTo method <script type="text/javascript">
Getting Cell Values in a JTable
Getting Cell Values in a JTable     ... values in a JTable component. It is a same as setting the cell values in a JTable... to get the cell values in a JTable. This program creates a JTable that contains some
Appending a Column in JTable
Appending a Column in JTable     ... in JTable. For adding a new column in JTable component you have to need a table model... of program: In this program, we will see how to add (append) a new column in JTable
Setting the Column Header in JTable
Setting the Column Header in JTable   ... the creation of JTable without column headers. In this example you will learn how to set the column headers in JTable using JTableHeader. Java provides some
accordion pane - Ajax
accordion pane  Is it possible to change the content of an accordion pane promgramatically? I wrote : function modif_pane1(){ dijit.layout.byId("pane1").content="string"; } but that's don't work
Changing the Name of Column in a JTable
Changing the Name of Column in a JTable   ... the name of column in JTable component. You have learnt the JTable containing ... the name in the name of column in a JTable in this following  example
Horizontal scroll bar?
Horizontal scroll bar?  Hi all, I have a HTTP Servlet... this. While the browser window automatically creates a vertical scroll bar, it does not automatically create a horizontal scroll bar when the data written exceeds
Inserting a Column in JTable
Inserting a Column in JTable     ... to insert a column in JTable at a specified location. As, you have learnt in previous section for inserting rows in JTable through using the insertRow() method

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.