How to add image in jtable header using 'Default table model'

Hi,
I created a table using "DefaultTableModel".
im able to add images in table cells but not in 'table header'.
i added inages in table by overriding "getColumnClass" of the DefaultTableModel.
But what to do for headers?
please help.
Thanks in advance.

The 'Java 5 tutorial' is really an outstanding oneI should note the the current tutorial on the Sun website has bee updated for Java 6. It contains updates to reflect the changes made in JDK6. Once of the changes is that sorting of tables is now supported directly which is why I needed to give you the link to the old tutorial.
http://java.sun.com/docs/books/tutorial/uiswing/TOC.html

Similar Messages

  • Is it posiible to paging up paging down in Jtable using Default Table Model

    Hi All!
    Is it possible to do Page up and Page down in JTable using Default Tble Model?
    Kindly reply!

    yes
    it is posiible to paging up paging down in Jtable using Default Table Model. just go thru the JAVA API you will get the results.

  • PageUp/PageDown By using Default Table Model

    Hi all,
    iam using Default Table model for my jtable i want to do pageup and pagedown operation .
    TableColumnModel cm1 = new DefaultTableColumnModel();
    DefaultTablemodel md = new DefaultTableModel(row,col);
    JTable t = new JTable(md,cm1);
    i have 500 rows currently in my database i want to display 100 in the first page and if i press the pagedown button the next 100 has to be diplayed wether this is possible here.. if possible please help mee.

    Hi,
    could you please avoid double posting:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=566380&tstart=0&trange=15
    especially with different subjects.
    It considerably reduces the overall efficiency as people will try to
    help you while the answer could already have been given in the another thread.
    If you want to push up the stack your message, reply to it,
    post more code, list the ideas that you've envisaged and so on.
    regards.

  • How to add  ComboBox in Jtable Header

    Hello everyone,
    I want to add a Combox box in JTable Header .Basically it works as central access to whole table e.g. by selecting delete row in combo box then it should delete the current selected row.If somebody has any idea please share it.
    Thanks in advance.

    The individual headers are not Swing components and therefore do not respond to mouse events in the same way as Swing components. Why don't you just have a popup menu that is positioned over the currently selected row? If you want to apply an action to all selected rows then have a set of buttons placed above the table header.

  • How to add image in ejb web service

    Hello Community,
    I am writing web service to create a PDF file using itext API. In PDF file i want to add an image.
    Can someone please tell that , how can i add image(jpeg, png , etc.) to an ejb web service?
    Thanks in advance
    Regards,
    Dishant Chawla

    Hi,
    Please check the below code which i used to add image to the header using iText . Similarly you can add image directly to the document also as a element.
    Adding image as Header:
    httpServletRequest = request.getServletRequest();
    domainURL=httpServletRequest.getScheme()+"://"+httpServletRequest.getServerName();
    imgLogo=domainURL+request.getWebResourcePath()+"/images/XXXX.jpg";
    image =Image.getInstance(imgLogo);
    image.scalePercent(22);// As per you need
    chunk = new Chunk(image, 0, -20);
    HeaderFooter header_pdf = new HeaderFooter(new Phrase(chunk), false); // here i have added image as header
    header_pdf.disableBorderSide(0);
    header_pdf.setAlignment(Element.ALIGN_CENTER);
    header_pdf.setBorder(0);
    document.setHeader(header_pdf);
    (or)
    Adding Image a Element:
    httpServletRequest = request.getServletRequest();
    domainURL=httpServletRequest.getScheme()+"://"+httpServletRequest.getServerName();
    imgLogo=domainURL+request.getWebResourcePath()+"/images/XXXX.jpg";
    image =Image.getInstance(imgLogo);
    image.scalePercent(22);
    document.add(image);
    Java IText: Image | tutorials.jenkov.com
    Regards,
    Srinivasan V

  • JTable Problem(Default Table Model)

    Hi all,
    iam using Default Table model for my jtable i want to do pageup and pagedown operation .
    TableColumnModel cm1 = new DefaultTableColumnModel();
    DefaultTablemodel md = new DefaultTableModel(row,col);
    JTable t = new JTable(md,cm1);
    i have 500 rows currently in my database i want to display 100 in the first page and if i press the pagedown button the next 100 has to be diplayed wether this is possible here.. if possible please help mee.

    sample code :
    // PagingModel.java
    // A larger table model that performs "paging" of its data. This model reports a
    // small number of rows (e.g., 100 or so) as a "page" of data. You can switch pages
    // to view all of the rows as needed using the pageDown( ) and pageUp( ) methods.
    // Presumably, access to the other pages of data is dictated by other GUI elements
    // such as up/down buttons, or maybe a text field that allows you to enter the page
    // number you want to display.
    import javax.swing.table.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class PagingModel extends AbstractTableModel {
    protected int pageSize;
    protected int pageOffset;
    protected Record[] data;
    public PagingModel( ) {
    this(10000, 100);
    public PagingModel(int numRows, int size) {
    data = new Record[numRows];
    pageSize = size;
    // Fill our table with random data (from the Record( ) constructor).
    for (int i=0; i < data.length; i++) {
    data[i] = new Record( );
    // Return values appropriate for the visible table part.
    public int getRowCount( ) { return Math.min(pageSize, data.length); }
    public int getColumnCount( ) { return Record.getColumnCount( ); }
    // Work only on the visible part of the table.
    public Object getValueAt(int row, int col) {
    int realRow = row + (pageOffset * pageSize);
    return data[realRow].getValueAt(col);
    public String getColumnName(int col) {
    return Record.getColumnName(col);
    // Use this method to figure out which page you are on.
    public int getPageOffset( ) { return pageOffset; }
    public int getPageCount( ) {
    return (int)Math.ceil((double)data.length / pageSize);
    // Use this method if you want to know how big the real table is. You could also
    // write "getRealValueAt( )" if needed.
    public int getRealRowCount( ) {
    return data.length;
    public int getPageSize( ) { return pageSize; }
    public void setPageSize(int s) {
    if (s == pageSize) { return; }
    int oldPageSize = pageSize;
    pageSize = s;
    pageOffset=(oldPageSize * pageOffset) / pageSize;
    fireTableDataChanged( );
    // Update the page offset and fire a data changed event (all rows).
    public void pageDown( ) {
    if (pageOffset < getPageCount( ) - 1) {
    pageOffset++;
    fireTableDataChanged( );
    // Update the page offset and fire a data changed (all rows).
    public void pageUp( ) {
    if (pageOffset > 0) {
    pageOffset--;
    fireTableDataChanged( );
    // We provide our own version of a scrollpane that includes
    // the Page Up and Page Down buttons by default.
    public static JScrollPane createPagingScrollPaneForTable(JTable jt) {
    JScrollPane jsp = new JScrollPane(jt);
    TableModel tmodel = jt.getModel( );
    // Don't choke if this is called on a regular table . . .
    if (! (tmodel instanceof PagingModel)) {
    return jsp;
    // Go ahead and build the real scrollpane.
    final PagingModel model = (PagingModel)tmodel;
    final JButton upButton = new JButton("Up");
    upButton.setEnabled(false); // Starts off at 0, so can't go up
    final JButton downButton = new JButton("Down");
    if (model.getPageCount( ) <= 1) {
    downButton.setEnabled(false); // One page...can't scroll down
    upButton.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent ae) {
    model.pageUp( );
    // If we hit the top of the data, disable the Page Up button.
    if (model.getPageOffset( ) == 0) {
    upButton.setEnabled(false);
    downButton.setEnabled(true);
    downButton.addActionListener(new ActionListener( ) {
    public void actionPerformed(ActionEvent ae) {
    model.pageDown( );
    // If we hit the bottom of the data, disable the Page Down button.
    if (model.getPageOffset( ) == (model.getPageCount( ) - 1)) {
    downButton.setEnabled(false);
    upButton.setEnabled(true);
    // Turn on the scrollbars; otherwise, we won't get our corners.
    jsp.setVerticalScrollBarPolicy
    (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    jsp.setHorizontalScrollBarPolicy
    (ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    // Add in the corners (page up/down).
    jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton);
    jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton);
    return jsp;
    // Record.java
    // A simple data structure for use with the PagingModel demo
    class Record {
    static String[] headers = { "Record Number", "Batch Number", "Reserved" };
    static int counter;
    String[] data;
    public Record( ) {
    data = new String[] { "" + (counter++), "" + System.currentTimeMillis( ),
    "Reserved" };
    public String getValueAt(int i) { return data[i]; }
    public static String getColumnName(int i) { return headers[i]; }
    public static int getColumnCount( ) { return headers.length; }
    class PagingTester extends JFrame {
    public PagingTester( ) {
    super("Paged JTable Test");
    setSize(300, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    PagingModel pm = new PagingModel( );
    JTable jt = new JTable(pm);
    // Use our own custom scrollpane.
    JScrollPane jsp = PagingModel.createPagingScrollPaneForTable(jt);
    getContentPane( ).add(jsp, BorderLayout.CENTER);
    public static void main(String args[]) {
    PagingTester pt = new PagingTester( );
    pt.setVisible(true);
    }

  • How do i add images in the header and footer to a PDF using iText

    Hi ,
    I want to add images to the header and footer of every page while i am genrating a pdf i have created a separate class called EndPage which i am instanceiating its default constructor in another class 's button action method.
    The above code genrates a PDF for me however it genrates a file with file size zero bytes and does not open it following is my sample code
    //**********Any Help would be appreciated
    Thank You
    public class My_Class
    public String pdf_action()
    EndPage ep=new EndPage();
    return null;
    }//My_class Ends
    class EndPage extends PdfPageEventHelper
    * Demonstrates the use of PageEvents.
    * @param args no arguments needed
    public EndPage()
    try {
    com.lowagie.text.Document document = new Document(PageSize.A4, 50, 50, 70, 70);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D://proposals/endpage.pdf"));
    writer.setPageEvent(new EndPage());
    document.open();
    String text = "Lots of text. ";
    for (int k = 0; k < 10; ++k)
    text += text;
    document.add(new Paragraph(text));
    document.close();
    catch (Exception de) {
    de.printStackTrace();
    public void onEndPage(PdfWriter writer, Document document) {
    try {
    Rectangle page = document.getPageSize();
    PdfPTable head = new PdfPTable(3);
    for (int k = 1; k <= 6; ++k)
    head.addCell("head " + k);
    head.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
    head.writeSelectedRows(0, -1, document.leftMargin(), page.height() - document.topMargin() + head.getTotalHeight(),
    writer.getDirectContent());
    PdfPTable foot = new PdfPTable(3);
    for (int k = 1; k <= 6; ++k)
    foot.addCell("foot " + k);
    foot.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
    foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
    writer.getDirectContent());
    catch (Exception e) {
    throw new ExceptionConverter(e);
    }

    Hi,
    Thanks for the quick response.
    The problem is that when I keep the logo as a watermark, the pdf is not adjusting itself to include the logo as header.
    But if I add a header text via Tools -> Headers and Footers, the pdf is adjusting itself so that the header text is at the beginning , not overlapping with the contents of pdf.
    But while using logo as watermark, some times overlapping of the pdf contents and logo is happening.
    Is there any way to add a logo in the Header and Footer via the option in Tools -> Headers and Footers
    Thanks,
    Vidhya

  • How to add Image dynamically in Webdynpro ABAP

    Hi Experts,
    How to add Image dynamically in Webdynpro ABAP.
    My requirement is i maintain all the images in a table.
    image source has to pick the table URl dynamically and display.
    is that possible in webdynpro?
    and also please give the suggesion,
    without using MIME objects is that anyway to get images?
    Thanks in advance.
    Regrads,
    Jeyanthi

    Hi,
      are those icons wou want to display then. he following code will be useful.
    data : lo_IMG type ref to CL_WD_IMAGE.
    LO_IMG = cl_wd_IMAGE=>new_IMAGE( id = img_id SOURCE = 'ICON_BW_APD_TARGET' tooltip = sts_tltp ).
    lo_cont->add_child( the_child = lo_img ).
    here lo_cont is the container where you want to add the image dynamically and source is the attribiute through which you can change the ICON image. this thing you can getit from data base table and change accordingly.
    Regards,
    Anil kumar G

  • How to add images to my PDF?

    Hi there
    I am wanting to know how to add images/photos to my PDF theta needs to be sent & signed to my supervisor?

    Hi Helen,
    You'll find the Add Image tool in the Content Editing pane of the Tools panel:
    If you don't see it there, make sure that you're using Acrobat, and not Adobe Reader, as these editing tools are unique to Acrobat.
    Best,
    Sara

  • I want to add image in column is it possible then how to add image in data base what data type we need to do

    I want to add image in column is it possible then how to add image in data base  what data type we need to give we required any casting  please show me one example
    jitendra

    Hi again,
    Several points that can help more:
    1. If you are working with Dot.Net, then I highly recommend read the first link that you got! This is nice and simple coding. Another option is this link which is even better in my opinion:
    http://www.dotnetgallery.com/kb/resource21-How-to-store-and-retrieve-images-from-SQL-server-database-using-aspnet.aspx
    2. As i mention above both link use the column's type image. There are several other option of working with Files. In most of my applications architecture I find that it is better to use a column which let us use any type of file and not an image column.
    In choosing the right column's type for your needs basically your fist question should be if if you want to store your data inside relational database environment or outside relational environment. It is a good idea to look for blogs on this issue. Next
    if you chose to store your data inside then you need to chose the right column type according to your server version. I highly recommend to look for blogs on the differences between those column's types: IMAGE, 
    Check those links:
    To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem
    http://research.microsoft.com/apps/pubs/default.aspx?id=64525
    FILESTREAM feature of SQL Server 2008
    http://msdn.microsoft.com/library/hh461480
    FileTables feature of SQL Server 2012
    http://technet.microsoft.com/en-us/library/ff929144.aspx
    Compare Options for Storing Blobs (SQL Server)
    http://technet.microsoft.com/en-us/library/hh403405.aspx
    Binary Large Object (Blob) Data (SQL Server)
    http://technet.microsoft.com/en-us/library/bb895234.aspx
    Managing BLOBs using SQL Server FileStream via EF and WCF streaming
    * Very nice tutorial!
    http://petermeinl.wordpress.com/2012/02/20/managing-blobs-using-sql-server-filestream-via-ef-and-wcf-streaming/
    [Personal Site] [Blog] [Facebook]

  • How to set height of JTable Header ?

    How to set height of JTable Header and set the text to another size ?

    You can set the font of the header as you can for any component. The font will dictate the preferred height of the header. If you don't like the preferred height, you can set that as well.
    // add table to a scroll pane or the header will not appear
    JTable table = new JTable(...);
    container.add(new JScrollPane(table));
    // get a reference to the header, set the font
    JTableHeader header = table.getTableHeader();
    header.setFont(new Font(...));
    // set the preferred height of the header to 50 pixels.
    // the width is ignored by the scroll pane.
    header.setPreferredSize(new Dimension(1, 50));Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • How to add images into a java application (not applet)

    Hello,
    I am new in java programming. I would like to know how to add images into a java application (not an applet). If i could get an standard example about how to add a image to a java application, I would apreciated it. Any help will be greatly apreciated.
    Thank you,
    Oscar

    Your' better off looking in the java 2d forum.
    package images;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.FileInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    /** * LogoImage is a class that is used to load images into the program */
    public class LogoImage extends JPanel {
         private BufferedImage image;
         private int factor = 1; /** Creates a new instance of ImagePanel */
         public LogoImage() {
              this(new Dimension(600, 50));
         public LogoImage(Dimension sz) {
              //setBackground(Color.green);      
              setPreferredSize(sz);
         public void setImage(BufferedImage im) {
              image = im;
              if (im != null) {
                   setPreferredSize(
                        new Dimension(image.getWidth(), image.getHeight()));
              } else {
                   setPreferredSize(new Dimension(200, 200));
         public void setImageSizeFactor(int factor) {
              this.factor = factor;
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              //paint background 
              Graphics2D g2D = (Graphics2D) g;
              //Draw image at its natural size first. 
              if (image != null) {
                   g2D.drawImage(image, null, 0, 0);
         public static LogoImage createImage(String filename) { /* Stream the logo gif file into an image object */
              LogoImage logoImage = new LogoImage();
              BufferedImage image;
              try {
                   FileInputStream fileInput =
                        new FileInputStream("images/" + filename);
                   image = ImageIO.read(fileInput);
                   logoImage =
                        new LogoImage(
                             new Dimension(image.getWidth(), image.getHeight()));
                   fileInput.close();
                   logoImage.setImage(image);
              } catch (Exception e) {
                   System.err.println(e);
              return logoImage;
         public static void main(String[] args) {
              JFrame jf = new JFrame("testImage");
              Container cp = jf.getContentPane();
              cp.add(LogoImage.createImage("logo.gif"), BorderLayout.CENTER);
              jf.setVisible(true);
              jf.pack();
    }Now you can use this class anywhere in your pgram to add a JPanel

  • How to add image file while creating addon...pathsetup?

    Hi friends,
    i have a problem while creating addon.
    while creating addon we can add all the files(.vb,xml).but if i add image files(.bmp,.jpg)they are not displayed in runtime.
    --how to add image file while creating addon..?
    we are useing SAP Business One 2005A(6.80.317)SP:01 PL:04

    Somebody knows like I can indicate to him to a button that I have in a form, that accedes to the image in the route where will settle addon? I have this, but it does not work to me
    oButton.Image = IO.Directory.GetParent(Application.StartupPath).ToString & "\CFL.BMP"

  • How to add color only in header

    how to add color only in header and arrange a background color selected from desktop

    You can place rectangle in header section on master page which would be applied on sub pages and then fill rectangle with color.
    If you are after a specific color then simply use color code and fill.
    Thanks,
    Sanjit

  • How can I change excel column header using Labile.

    Dear Experts,
                          How can i change excel column header using LabVIEW.
    Thanks for any and all help!
    M.S.Sivaraj.
    Sivaraj M.S
    CLD

    As I said in my previous post, column headers in Excel are merely row 1 cells. May be I missing something here, so please be more explicit with your question.
    I guess you are using the Excel Report tools, and you want to modify an existing sheet. From my limited experience with the Excel Report tools, it is not possible to open an existing woorkbook (except as template...), so the answer to your question should be "Forget it"...
    The work around is to use the example I pointed for you before, and either to write the whole new colum headers as a string array, starting in A1, or to write a single string to a given cell in row 1.
    Hope this helps 
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

Maybe you are looking for