Adding mouse listener to the column header of a column in a JTable

Hi
I want to add a mouse listener to the column header of the 3rd column in a JTable. I dont find any appropriate method to do this. The code I have written to do this is below. But on using this code, the mouselistener is invoked if I click on any column header. Can anyone please help me to fix this.
table.getTableHeader().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
/* some actions */
}

      table.getTableHeader().addMouseListener(new MouseAdapter(){
           public void mousePressed(MouseEvent me) {
               int tableColumn  =table.columnAtPoint(me.getPoint());//it returns the column index
        });

Similar Messages

  • How to set the column width of JTable

    I want do remember the column width and write it to a file, when the window is started , the column width is read from the file and the table is set as that. I also want the column width is not fixed and can be changed by mouse.But I am always failded.
    How to do? would you please help me!
    Thanks a lots.

    To "remember" the column widths, add a mouse listener to the table header. Upon mouseReleased(), get the column widths and save them to your file. When the application starts next time, get the stored widths and set them using:
    table.getColumn("XXX").setPreferredWidth(...);
    By default, your columns are adjustable, but you can use:
    table.getTableHeader().setResizingAllowed(true);

  • Can i stop the columns in a JTable from re-ordering?

    Hi,
    As we know, JTable by default allows re-ordering of the columns within it.
    I mean to say that the columns in a JTable can be interchanged, by drag and drop utility.
    I want to refrain my JTable from doing so.
    Can someone please suggest me how can i do this?
    Thanx in advance :)
    Regards,
    Archana

    Thank you :)
    This did solve my problem of columns getting re-ordered in my JTable.
    But i am facing one more problem now :(
    I sort my JTable by clicking on the JTableHeader.
    Clicking on the column header of any one of the columns of the JTable, sorts all entries in either ascending or descending order.
    This is not happening.:(
    Can someone please help me out?
    Thanx in advance :)
    Regards,
    Archana

  • Adding more Values to the Column Link in Apex

    Hi,
    Is there any possibility of adding extra or more values to the column link in Apex. I already have 3 Column Name and Values linked to a different report.
    Eg:-
    Column Link:
    Link Text : #COUNT#
    Name       Value
    DATE #DATE#
    PRICE #PRICE#
    COST #COST#
    I want to add one more Name like 'ID' and corresponding and Value #ID#.
    Please Help...
    Thanks in Advance..
    Edited by: user13561710 on Jan 10, 2011 9:20 AM
    Edited by: user13561710 on Jan 10, 2011 12:34 PM

    Thanks Varad,
    But it didn't worked, The page has option to link only 3 values.
    My Target is 'Page in this Application" not a URL.
    I used your format and if you apply changes and come back the whole thing is dissappeared and even the link to page in application is inactive.
    Is there any other way???
    Thanks
    Edited by: user13561710 on Jan 10, 2011 10:49 AM
    Edited by: user13561710 on Jan 10, 2011 12:35 PM

  • Mouse Move on the column Chart

    Hi all visitors
    I have created one crystal report and in my report i have created one column chart.
    but i don't show the value on the column chart,however, when i move mouse on that column chart,
    it will show the value.but in crystal report server,when i move the mouse on the column, it doesn't show the value like crystal report.
    Anyone know about this how to show the value on the column when mouse move in crystal report server?
    Please help me for this.
    Best Regards,

    Unfortunate Tool tip doesn't work with CR Charts.
    Probably there may be some  trick that will configure to achieve. But I didn't came across till now.

  • EEWB and adding additional fields to the IBASE header

    Hello,
    I have used the EEWB (Easy Enhancement WorkBench) to add additional fields to the IBASE header. The process ends with a success state and in all steps there are no logs. The objects are generated and visible in the database table of the IBASE header and activated.
    When I go to the IB53 transaction the systems starts compiling. After the compiling there are no additional fields visible?
    In the EEWB no more actions are possible and it seems only an append structure was created with the new fields (GENERIC_IC_TASK).
    How do I get the fields to be visible in the IBASE transaction?
    I am using CRM 5.0.

    Ramakanth/Kiran,
    For creating screen structures or additional fields on the IBase header screen you would need to manually append entries in Database Tables T371D.... through T371Z, it is a set of around12-14 tables depending on the scenario which would need updations.
    Once updated in the right sequence you can see the EEWB fields on the Ibase header screen.
    Hope this helps.
    Amit Sitlani

  • Adding element RelatesTo to the soap header

    Hi All,
    I need to replace wsa05:MessageID element in the soap header with the following value
    <wsa05:MessageID>fn-bea:uuid()</wsa05:MessageID>
    <wsa05:RelatesTo>$header/wsa05:MessageID/text()</wsa05:RelatesTo>
    How would I do that in OSB proxy service?

    You may use Insert or Assign or Replace action -
    http://download.oracle.com/docs/cd/E17904_01/doc.1111/e15867/proxy_actions.htm#CIHEFDFB
    Regards,
    Anuj

  • How could i listen to the column width changed event of a tableview

    I really want to do some painting when the column is resized manually.
    but it seems that there's not a column reszie event in javafx, is there?

    TableColumn dateCol = new TableColumn("Date");
    dateCol.setCellValueFactory(new PropertyValueFactory("longrowid"));
    dateCol.widthProperty().addListener(new ChangeListener(){
            @Override public void changed(ObservableValue o,Object oldVal,
                     Object newVal){
                 System.out.println("Width property has changed!");
          });

  • Adding content will resize the column

    I'll create a table and then whenever I add content to any
    cell, that whole column will resize (even if the content did not
    fill the whole width of the column). How can I stop the columns
    from resizing whenever I add content in it?

    That's how table cells work -they stretch or shrink depending
    on the content
    within them.
    What exactly are you trying to do - can you link a sample
    page and explain
    what exactly you are having problems with - there are
    probably ways to
    overcome your issues.
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    ~ Customisation Service Available ~
    http://www.csstemplates.com.au
    "RHucal" <[email protected]> wrote in
    message
    news:f6uqcf$i0o$[email protected]..
    > I'll create a table and then whenever I add content to
    any cell, that
    > whole
    > column will resize (even if the content did not fill the
    whole width of
    > the
    > column). How can I stop the columns from resizing
    whenever I add content
    > in it?
    >

  • Giving names to the columns in a JTable

    Hi,
    I am using JTable(int numRows, int numColumns) constructor to create a JTable. After I built my application I came to knw that I cannot change the column names. The JTable in my GUI will keep on changing and the no. of rows,columns and even the column names may also change. I just wanted to know what constructor I should shift to.
    Thanks,
    Adhiraj

    I would use something like the following:
    DefaultTableModel model = new DefaultTableModel(columnNames, rowCount);
    JTable table = new JTable( model );
    The following code gives some examples on using the DefaultTableModel to add rows and columns:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class TableRowColumn extends JFrame
         private final static String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         JTable table;
         DefaultTableModel model;
         JPanel buttonPanel;
         JButton button;
         public TableRowColumn()
              //  Create table
              Object[][] data = { {"1", "A"}, {"2", "B"}, {"3", "C"} };
              String[] columnNames = {"Number","Letter"};
              model = new DefaultTableModel(data, columnNames);
              table = new JTable(model);
              table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
              //  Add table and a Button panel to the frame
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              buttonPanel = new JPanel();
              getContentPane().add( buttonPanel, BorderLayout.SOUTH );
              button = new JButton( "Add Row" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        model.addRow( createRow() );
                        int row = table.getRowCount() - 1;
                        table.changeSelection(row, 0, false, false);
                        table.requestFocusInWindow();
              button = new JButton( "Insert Row" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        model.insertRow( 0, createRow() );
                        table.changeSelection(0, 0, false, false);
                        table.requestFocusInWindow();
              button = new JButton( "Empty Row" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        model.setRowCount( model.getRowCount() + 1 );
                        int row = table.getRowCount() - 1;
                        table.changeSelection(row, 0, false, false);
                        table.requestFocusInWindow();
              button = new JButton( "Add Column" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        String header = "Col" + (table.getColumnCount() + 1);
                        model.addColumn( header );
                        table.requestFocusInWindow();
              button = new JButton( "Add Column & Data" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        String header = "Col" + (table.getColumnCount() + 1);
                        int rows = table.getRowCount();
                        String[] values = new String[rows];
                        for (int j = 0; j < rows; j++)
                             values[j] = Integer.toString(j);
                        model.addColumn( header, values );
                        table.requestFocusInWindow();
              button = new JButton( "Add Column - No Reordering" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        //  Use this method when you don't want existing columns
                        //  to be rebuilt from the model.
                        //  (ie. moved columns will not be reordered)
                        table.setAutoCreateColumnsFromModel( false );
                        String header = "Col" + (table.getColumnCount() + 1);
                        model.addColumn( header );
                        //  AutoCreate is turned off so create table column here
                        TableColumn column = new TableColumn( table.getColumnCount() );
                        column.setHeaderValue( header );
                        table.addColumn( column );
                        // These won't work once setAutoCreate... has been set to false
                        buttonPanel.getComponent(3).setEnabled( false );
                        buttonPanel.getComponent(4).setEnabled( false );
                        table.requestFocusInWindow();
              button = new JButton( "Remove Last Column" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        int columns = model.getColumnCount();
                        if (columns > 0)
                             if (!table.getAutoCreateColumnsFromModel())
                                  int view =
                                       table.convertColumnIndexToView(columns - 1);
                                  TableColumn column =
                                       table.getColumnModel().getColumn(view);
                                  table.getColumnModel().removeColumn( column );
                             model.setColumnCount(columns - 1);
                        table.requestFocusInWindow();
         private Object[] createRow()
              Object[] newRow = new Object[2];
              int row = table.getRowCount() + 1;
              newRow[0] = Integer.toString( row );
              newRow[1] = LETTERS.substring(row-1, row);
              return newRow;
         public static void main(String[] args)
              TableRowColumn frame = new TableRowColumn();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • How can I restrict the column dragging of JTable?

    I have a requirement like, if we have any editable cell in the JTable, we should not allow the user to drag the columns at all. I tried with setDragEnabled(false) ..but its not giving the proper out put..... can any one come up with a solution for this?

    table.getTableHeader().setReorderingAllowed(false)

  • Changing the color of the column in a JTable based on the selection (mouse)

    Hi,
    I want to change the color of all the cells in a column based on the mouse clicked event.
    I have managed to select the entire column. And, even, I have found a working example in the internet. But I don't understand why in my case it doesn't work.
    This is the code (an inner class for a TableCellRenderer):
    class MCTableCellRenderer extends JLabel implements TableCellRenderer {
              private static final long serialVersionUID = 1L;
              @Override
              public Component getTableCellRendererComponent(JTable table,
                        Object value, boolean isSelected, boolean hasFocus, int row,
                        int column) {
                   setFont(table.getFont());
                   if(value instanceof Double){
                        setHorizontalAlignment(SwingConstants.RIGHT);
                        DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance();
                        numberFormat.applyPattern("#######.#");
                        String val = numberFormat.format(value);
                        setText(val);
                   if(isSelected){
                        setBackground(Color.RED);
                        System.out.println("is selected");
                   else{
                        setBackground(Color.BLACK);
                        System.out.println("is not selected");
                   return this;
        }I have set opacity to true for the contentPane, but without any result.
    Any advice will be very apreciated.

    Problem solved.
    My Renderer should have extended the abstract class DefaultTableCellRenderer.
    class MCTableCellRenderer extends DefaultTableCellRenderer {

  • How to set the column width in the PDF exports of interactive reports ?

    Hello,
    I have a huge problem with the PDF export for the Interactive reports. I'm using APEX 3.2.
    I have to produce a PDF report in landscape format that show 21 columns. My problem is that the columns have a ridiculous short width and that the text inside the columns do not wrap in the columns. So I get things like that :
    Date Name
    2011 Leina
    I should see 2011-08-01 and the name Leinad Jan
    I tried several things to format the columns, but none of the them has any effect on the PDF itself.
    1) I used HTML code in the report query. It works well with the interactive report, but display the HTML tags in the PDF.
    2) I used css to set the width of my columns. It works in the interactive report, but not in the PDF, the column width do not change.
    It's like the report do not notice that my page format is Legal 14 x 8.5 (Landscape) and still believe it's 8.5 x 11 (which is "portrait")
    Do you have any idea so set the columkn widths in the reports ?
    Thank you !
    Edited by: leinadjan on Aug 1, 2011 11:15 AM

    To "remember" the column widths, add a mouse listener to the table header. Upon mouseReleased(), get the column widths and save them to your file. When the application starts next time, get the stored widths and set them using:
    table.getColumn("XXX").setPreferredWidth(...);
    By default, your columns are adjustable, but you can use:
    table.getTableHeader().setResizingAllowed(true);

  • Problem in Adding two buttons under same column header (in JTable)

    Hi,
    I have a JTable and to a particular column i want to add two buttons.
    Here the two buttons should be under the same column header and i need to add listners to these.
    Any idea how to do this?
    Thanks & regards
    Neel

    Of course as your header is drawn by a renderer, the buttons don't actually work, but you can listen for mouse clicks within the area of the header and see which button the mouse position was over.
    See the Java Table Sorter Demo code for how to add a mouse listener to the header...
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html#TableSorterDemo
    ....and from there you should be able to determine where in the component the click occured by using the getX() and getY() methods of the MouseEvent to determine which button in the renderer component was clicked. Use something like Rectangle.contains() to match the click location against the buttons.

  • Is it possible to disable the mouse automatically scrolling the video playback head?

    Previous versions of iMovie allowed me to move the mouse without moving the playback head.  Doesn't appear possible in '11.  Can it be toggled?
    Thanks.
    Lindy

    No.  If I run the mouse over a video in iMovie, the video automatically scrolls along with the mouse.  The audio skimming function (if on) allows me to hear the audio along with the video as it scrolls - a useful feature, but not what I'm trying to fix.
    What I'd like to be able to do is turn all of that off so that the only way to play a video is to start it with the space bar.
    As it is now, if I select a spot where I'd like to place a marker or split a video, I have to move the mouse in order to initiate the command that I want.  But the moment I move the mouse to go to a menu, the video moves to a different place, making the edit more difficult.
    iMovieHD ('08) did not have the scrolling function, and while I appreciate the usefulness of having it, I'm struggling with being unable to turn it off.  I could play a video to the point where I wanted to edit it, fine tune the playback head location and perform the edit without so much as touching the mouse.
    It's not that I'm incapable of doing what I need to do with iMovie the way it is.  It just seems a bit tougher to accomplish these things with the scrolling when I don't want it to.  Seems like it should be a Preferences setting or something.  But I can't find it.
    Thanks.
    Lindy

Maybe you are looking for

  • T550 New design ergonomics

    From what I can see from product pictures on T550 and w550s models, Lenovo has made the palmrest longer i.e. it appears at least 2cm longer than other models such as t540p, e550 or w540. I am currently using a MacBook pro which has a palmrest that is

  • RFC Sender error could not create function template for...

    Hi, I am trying to send an async RFC to XI. Since I use IN BACKGROUND TASK and COMMIT WORK I got following error in the SM58 of the back end system Server repository could not create function template for 'XYZ' In the XI, I see nothing (no message, n

  • EXCEL CALCULATION IN CALCULATED COLUMN PROBLEM

    Hello, Please someone kindly help out with this calculation problem. I have an Excel file with this calculation: =IF(E10<D10,E10/D10,E10/E10) I am trying to translate this into a calculated column in a list and I can't seem to succeed with it. Can an

  • Iphone backup on iOS X Lion

    Hi, I upgraded my iOS 10.6 (Leopard) to iOS X 10.7 (Lion) recently and now I no longer can find my iPhone backup file that used to be in ~/Library/Application Support/MobileSync/Backup.  The Library folder seems to have just disappeared. Does anyone

  • SunOS 5.10 zones

    Hello. We have a server, with SunOs 5.10, running two zones. My question is how do you set the maximal file descriptor and how does that effect the two zones. Lets say the fd_max is set to 4096. Does that mean the two zones have 4096 each (2*4096) or