Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners JTABLE SCROLL PANE

Have Programming Question? Ask it here!
 
 
 


DEEpanshu
JTABLE SCROLL PANE
0 Answer(s)      a year and 10 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; } } }


Advertisement
View Answers

Related Tutorials/Questions & Answers:
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
Advertisements
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
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
Scroll ImagesUIScrollView
Scroll ImagesUIScrollView  Hi, Can anyone please suggest me how to scroll images in UIScrollView in iPad? THanks
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
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
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
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
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
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
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
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">
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
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
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
Regarding Scroll Bar - CVS
Regarding Scroll Bar  HI all, i have a Text Message box which i have incorporated in my code which goes something like
Press button and Scroll Image to Scrollpanel
Press button and Scroll Image to Scrollpanel  Insert image into the jpanel,inside the jscrollpane.If i press the button and scroll image
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
how add tabs at the left side of a pane
how add tabs at the left side of a pane  sir i have added the tabs at the top left corner of the pane, but i am unable to add it at the left side of the pane, so please help me
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
jtable problem
jtable problem  how to make a cell text hypertext
scroll bars to list box - JSP-Servlet
scroll bars to list box  Can I add scroll bars to a list box in struts?  Hi friend, Scroll the list box in struts Two attribute set "multiple" "size". Select Tag Example Select Tag
how to scroll multiple images using on Click in Android
how to scroll multiple images using on Click in Android  I am new android platform, now i am working with small application. here... to scroll multiple images. But i am able to scroll single image. plz let me know
JTABLE OF JAVA
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
Jtable-Java
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
Create a Desktop Pane Container in Java
Create a Desktop Pane Container in Java   ... pane container in Java. The desktop pane container is a container, which has.... The desktop pane is like a MDI (Multiple Document Interface) frame and all internal
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
Display message on scroll Event
Display message on scroll Event In this tutorial, we will discuss about how to display message on scrolling of text area using jQuery scroll event. In this example, a text area with scroll bars are given , when we scroll any one
JTABLE Issue
JTABLE Issue  Hi Eveyone, I am developing a small application on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... on basis of input data provided in input field. For JTABLE is on some other
The scroll browser event of jQuery
The scroll browser event of jQuery In this tutorial ,we will print message on browser's window scrolling using scroll browser event of jQuery. In this example, some paragraphs are written , when we scroll down, a message
jtable query
jtable query  I need a syntax...where i could fetch the whole data from the database once i click the cell in jtable...and that must be displayed in the nearby text field which i have set in the same frame
java jtable
java jtable  Hello Sir, I am developing a desktop application in which i have to display database records in jtable .now I want to read only... that in jtable. plz help me with the code
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
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container... a container on the jtable. kindly help me sir. thanks in advance regards, rajahari
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
REPORT WITH JTABLE
(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's... { JFrame f; JPanel p; JLabel l; JTextField tf; JButton btn; JTable tb
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
 

 

 

DMCA.com