Multiple Icon on Jtable header

Hi All:
Any one had used multiple icons on JTable header ? According to the user's clicking positon under one column, one of these icons should change such as changing from sorting up arrows to sorting down arrows.
I got the mouse clicking position on the header and column, then depend on the location, I wanted to perfrom different things. But I have not figured out if I should call header renderer to perform the repaint or not ? If I use JTable header render, how should I confine the one column that change should happen? I don't want to have all columns repainted. If I treat each column indivisually, should I reconstruct the JTable ? I used SortableTableModel to create the JTable.
Any help is appreciated.
Regards

Here's the idea. I didn't test thisclass JComponentCellRenderer extends JButton implements TableCellRenderer {
    public JComponentCellRenderer (ImageIcon ii) { super("",ii); }
    public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
        setText(value.toString());
        return this;
}and thentblChanges.getColumnModel().getColumn(0).setHeaderRenderer(new JComponentCellRenderer(new ImageIcon( "CheckBoxHeaderImage" )));

Similar Messages

  • Free alternatives to JTable that allow multiple rows in the header?

    My goal is to make a table with two or more rows in the column header. For instance, imagine I want to have the numbers of the days in the calendar as columns, then I want to have a row over them with the months, spanning over multiple days, then I want to have a row over that with the year, spanning over multiple months. I want these rows to be in the column header so they're always visible as you scroll down.
    Right now, I'm doing this with the first rows of the grid, out of the header, so they get out of view when the user scrolls down. Also, by being in the actual grid, they screw up sorting of the table.
    So I need 2 features. Multiple rows in the column header and the ability to merge multiple cells in the header.
    I've see some code to do this but it seemed too complicated so I want to see if I can find a component that does this out of the box first. I've seen 2 3rd party JTable-based components that do this but they're paid products and paying the full price of a component bundle for these features isn't a very attractive idea.
    So, does anyone know of a good table component that does this?

    Have a look at JXTable from the SwingX project. You should be able to find it via Google.

  • JComboBox in the JTable Header - TableCellEditor problem

    Hi,
    I have added JComboBox into the JTableHeader. But I can't Edit that combobox. It is looking like an icon. I have added JPanel into the JTable Header Row. In JPanel i have added one JLable and JComboBox.
    Please any one of you give me the solution.
    Thanks,
    Shrini V.

    The table will display what ever value it has in its model. When you add the row, there is no data in the second column. You'll have to supply it.
    public void insertMyRowCombo (Object [] r,
                                      JComboBox c,
                                      JTable t) {
           // {"rut", "puntaje cas", "beneficio", "fecha inicio", "fecha termino", "monto"};
            DefaultTableModel tm = (DefaultTableModel) t.getModel();
            tm.addRow(r);
            TableColumn col = t.getColumnModel().getColumn(2);
            col.setCellEditor(new DefaultCellEditor(c));
            tm.setValueAt( c.getItemAt(0), 0, 2); //manually supply the value to col 2
        }ICE

  • Draw image over jtable header

    hello, I am trying to draw an image (its a little image of a custom sort indicator) over the header of a jTable, but after extensive reading of the api docs about TableCellRenderer and DefaultTableCellRenderer I cannot come to a solution.
    What I want is something like this: let the renderer do the paint and after that I grab the graphics and draw the image over it...
    please let me know if I need to restate my problem

    I extended DefaultTableCellRenderer like you say in your article, but while doing so it lost the default Metal L&F. It become like an ordinary cell of the table. Below is the code:
    class DefaultTableHeaderCellRenderer extends javax.swing.table.DefaultTableCellRenderer {
       @Override
       public Component getTableCellRendererComponent(JTable table, Object value,
             boolean isSelected, boolean hasFocus, int row, int column)
          super.getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
          //setIcon(getIcon(table, column));
          setBorder(UIManager.getBorder("TableHeader.cellBorder"));
          return this;
        protected Icon getIcon(JTable table, int column) {
           ImageIcon icon = new ImageIcon("imagens/sortdown.png");
           return icon;
    }then in my class I call:
    this.getTableHeader().setDefaultRenderer(new DefaultTableHeaderCellRenderer());You can see I commented setIcon. It works, the icon is drawn, but this is not what I am after, I wanted to draw the icon over the Metal L&F. Also, is there a way to draw the icon at a specified position?
    thanks for the help

  • How do i change the cursor on a jtable header when clicked for sorting?

    here is my question, how do i change the cursor on a jtable header when I click the header for sorting?
    I think it is suppose to be in the fragment of code where the header listener is implemented for sorting, but I'm not quite sure what is the exact component that holds everything so that i can change the cursor...
    below is what I've tried, but it doesn't seem to work... thank you
    public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new
    MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    TableColumnModel columnModel =
    tableView.getColumnModel();
    int viewColumn =
    columnModel.getColumnIndexAtX(e.getX());
    int column =
    tableView.convertColumnIndexToModel
    (viewColumn);
    System.out.println("column = "+column);
    if (e.getClickCount() == 1 && column != -1) {
    System.out.println("Sorting ...");
    Cursor oldCursor =
    tableView.getRootPane().getCursor();
    System.out.println("oldCursor.getType()
    = "+oldCursor.getType());
    if (oldCursor.getType() !=
    Cursor.WAIT_CURSOR){
    JComponent parentPane =
    tableView.getRootPane();
    parentPane.getContentPane().setCursor
    (new Cursor(Cursor.WAIT_CURSOR));
    parentPane.setCursor(new Cursor
    (Cursor.WAIT_CURSOR));
    Cursor newCursor =
    parentPane.getCursor();
    System.out.println("newCursor.getType
    () = "+newCursor.getType());
    int shiftPressed = e.getModifiers(
    &InputEvent.SHIFT_MASK;
    boolean ascending = (shiftPressed == 0);
    //System.out.println("tableView.getRootPane()
    is "+tableView.getRootPane().getRootPane());
    sorter.sortByColumn(column, ascending);
    tableView.getRootPane().setCursor(new Cursor
    (Cursor.DEFAULT_CURSOR));
    //System.out.println("Done sorting");
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
    }

    Hi,
    Try setting the cursor for the table header.
    table.getHeader().setCursor(Wait_Cursor);
    Bala.

  • Is there an easy way to move multiple icons from one screen to another?

    I have multiple screens on my iphone 5c display.  I want to move multiple icons at the same time from one screen to another.  Is there a way to do this?

    You could put them all in a single folder and move the folder to another screen.

  • How to Insert Multiple Icons in a Canvas?

    Hi All
    I am new to MIDlets so I need some initial help related to UI generation in MIDlets.
    I have to Insert multiple Icons in a canvas.
    These Icon should behave like button i.e. all Icon must have key-pressed event separately(i.e.
    when any particular Icon will be selected(positioned whatever) some action will be performed.
    same like in smart phone a single screen contains multiple icon for multiple operations to be
    performed.
    Is it possible in single canvas or I have to make multiple canvas for each icons?
    Any suggestion will be appreciated
    Thanks
    Nitesh.

    Hi ,,
    In Bex analyzer (BI 7.0) i am getting the option tools-> insert query??
    Do i need to configure anywhere to get this option //
    Can you please give details on that.
    Thanks,
    Debasish

  • 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.

  • Not able to edit the JTextField under the JTable header

    Hi,
    As per my requirement, i need to add the text field in JTable header for filtering the table records.
    i have added the text field but not able to enter any value (it is disabled).
    Can anyone please help me on this?

    Welcome to the forum.
    After reading how to format Code in this forum (SQL and PL/SQL FAQ ),
    please show us the code of your TableHeader implementation.
    bye
    TPD

  • 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]

  • Custom button icons in application header

    Hi All,
    I have a requirement, where I want to provide ability to end user to supply custom icons in application header.
    For this I have created a class and extended from sap.m.Button.
    and override setIcon method in my child class?
    but could not get this to work? can someone help me out?
    regards

    Any pointers please help.
    I am now able to display the icons.But how do I prevent expand/collapse on icon click?

  • Multiple selection in JTable for deletion

    Dears,
    I'm using Jdeveloper 9.0.3.3 on 8.1.7 Oracle DB.
    I noticed that when a JTable is bound to a View object ==> only one row can be selected.
    My situation -which I think is very common- I have a screen with JTable where I can edit a row and commit my updates or select multiple selection in JTable and delete them at once ; thats what I need.
    It is very like the test of any application module but allow multiple selection and deletion in JTable for user's selected rows.
    How this could be done in JClient?
    Thankx in advance.

    Thanks for your suggestions! They both would work as workarounds, I think. I tried another way:
    Following code changes a TableBinding bound JTable's selection model to Multi select (thanks to Shailesh!!).
    void setMultiSelectionModel(JTable tbl)
    class MultiSelectionListListener implements javax.swing.event.ListSelectionListener
    ListSelectionModel defSelModel;
    MultiSelectionListListener(ListSelectionModel model)
    defSelModel = model;
    public void valueChanged(javax.swing.event.ListSelectionEvent e)
    if (!e.getValueIsAdjusting())
    ListSelectionModel listModel = (ListSelectionModel)e.getSource();
    int leadIndex = listModel.getLeadSelectionIndex();
    if (leadIndex == listModel.getAnchorSelectionIndex()
    && leadIndex == listModel.getMaxSelectionIndex()
    && leadIndex == listModel.getMinSelectionIndex())
    //change currency on the bound iterator only if
    //one row is being selected.
    defSelModel.setSelectionInterval(leadIndex, leadIndex);
    ListSelectionModel newModel = new DefaultListSelectionModel();
    newModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    newModel.addListSelectionListener(new MultiSelectionListListener(tbl.getSelectionModel()));
    tbl.setSelectionModel(newModel);
    This fixes the bug if you select some rows and then select a row before the first selected one. Seems to work great.

  • Changing multiple icons?

    Hi,
    Is there a way I can change multiple icons of folders, subfolders and their content?
    I have all my music on an ext. HD, with it organised into artists>album>songs and a similar setup on another HD for video files with organisation being TV show>season>episodes. I would like all audio files and folders to have the same icon and all video files and folders the same as well.
    Is there anyway I can do this without the labour intensive task of opening each folder, going ot the the "Get Inf" for each file or folder within it and pasting my preferred icon??
    Thanks
    E

    You can do it with just the OS.
    First, copy the icon you want to use to the Clipbioard (Command-C).
    Then open a folder containing files which you want to change. Slect all the ones you want to have the icon on the Clipboard; if it's all the ones in the folder, just press Command A.
    Then press Command-I (Get Info) without clicking on one of the selected files. A single Get Info window will open, showing the number of files selected as the 'name'.
    Click the icon at the top of that Get Info window, press Command-V (Paste), and in a few seconds all the selected files will display the same icon, the one you had copied to the Clipboard.
    Folder icons - I would do those individually, unless you have hundreds. You can, of course, experiment with the same technique with a bunch of those.

  • Multiple icons/images in detailed List view?

    How can I view multiple icons in the detailed list view?
    Forte rel 3.0.F.2
    Nikola Filipovic, DMC Inc
    @ Nesbitt Burns Inc
    Tel. 416.359.7447

    https://bugs.archlinux.org/task/32369
    Please Google before you seek help.

  • Changing jtable header when moving down

    Hi,
    I would need changing Jtable header, when the cursor switches between lines
    How to do this ???
    Best Regards
    S.Ancelot

    1) You could create a second table header and replace the old one using scrollPane.setColumnHeaderView(...)
    2) Or, you could simply change the values in each TableColumn and then repaint the header.

Maybe you are looking for

  • Help with Buttons for Slideshow

    I'm working on my first flash project.  I have created a simple 4 image slideshow.  I have created 4 Buttons that when clicked, jump to that image in the timeline.  I have added Rollover States to the button. Everything is working like I want it to.

  • DTP Filters Identification

    Hello, In a DTP process I need to select some records with these conditions: If a Posting Date Range is entered in the DTPu2019s Filter Window then the process will be the standard, all records will be filtered using the entered date and moved to som

  • Connection timeout error keeps on occurring on my new Macbook Pro, please help?

    I recently bought my Macbook Pro and the software version is OS X 10.8.2. I keep on having "Connection time out error" and I can't use the internet, while my old laptop and iPhone can use it without a problem. This keeps on occurring and I am new to

  • Create paragraph style based on selection

    Is there a way to create a paragraph style based on the selection in the same way the "New Paragraph Style" dialog box does without having to go through ALL of the elements of the style individually? Thanks

  • SMART Not  So SMART?

    Some weeks ago my PowerBook hard disk showed some bad sectors. Trying to repair it with Disk Warrior, TechTools and Disk Utility all had mixed results. THEN Disk Utility reported that SMART had reported a Fatal failure. After that none of the utiliti