Results 1 to 5 of 5
  1. #1
    Clarion is offline Member
    Join Date
    Jun 2008
    Posts
    2
    Rep Power
    0

    Default Jframe In Jtable cell

    hai,

    Can Anyone help me to create a Jframe in Jtable cell as we create popmenu and dialog box on click event..

    just send the code ..

    clarion

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    It's better try something first yourself. We don't take homeworks for others. Try something my friend. If you stuck with some, ask here. :)

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    just send the code ..
    No

    That kind of statement ruffles my feathers. As noted above it is better for you to try yourself. Also, if this component will be seen within the JTable it can't be a JFrame, a JDialog or any other root container. It is ok being a JPanel however.

  4. #4
    Clarion is offline Member
    Join Date
    Jun 2008
    Posts
    2
    Rep Power
    0

    Default

    hai friends,
    I am really sorry for sending like that...(Just send the code)...Dont mistake me Past 2 weeks I started working in java.Just i tried something,here the code of my program....(this also i have taken from net and editted according to my need)....

    I have attached only my main class here....
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;

    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.BorderFactory;
    import javax.swing.DefaultCellEditor;
    import javax.swing.InputMap;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.KeyStroke;

    public class Test extends JFrame {
    JTable table;

    public Test() {
    table = new JTable(15, 5) {
    public boolean isCellEditable(int row, int column) {
    return column % 2 == 0;
    // return true;
    }

    public void changeSelection(final int row, final int column,
    boolean toggle, boolean extend) {

    super.changeSelection(row, column, toggle, extend);

    if (editCellAt(row, column)) {
    getEditorComponent().requestFocusInWindow();
    }
    }

    };

    table.setPreferredScrollableViewportSize(table.get PreferredSize());
    table.putClientProperty("terminateEditOnFocusLost" , Boolean.TRUE);

    TextAreaRenderer textAreaRenderer = new TextAreaRenderer();
    TextAreaEditor textEditor = new TextAreaEditor();
    table.getColumnModel().getColumn(4).setCellRendere r(textAreaRenderer);
    table.getColumnModel().getColumn(4).setCellEditor( textEditor);

    JTextField tf = new JTextField();
    tf.setBorder(BorderFactory.createEmptyBorder());
    table.setDefaultEditor(Object.class, new DefaultCellEditor((tf)));

    JScrollPane scrollPane = new JScrollPane(table);

    DefaultCellEditor dce = (DefaultCellEditor) table
    .getDefaultEditor(Object.class);
    dce.setClickCountToStart(1);

    getContentPane().add(scrollPane);

    InputMap im = table
    .getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPO NENT);

    // Have the enter key work the same as the tab key

    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    im.put(enter, im.get(tab));

    // Disable the right arrow key

    KeyStroke right = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0);
    im.put(right, "none");

    // Override the default tab behaviour
    // Tab to the next editable cell. When no editable cells goto next cell.

    final Action oldTabAction = table.getActionMap().get(im.get(tab));
    Action tabAction = new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
    oldTabAction.actionPerformed(e);
    JTable table = (JTable) e.getSource();
    int rowCount = table.getRowCount();
    int columnCount = table.getColumnCount();
    int row = table.getSelectedRow();
    int column = table.getSelectedColumn();

    while (!table.isCellEditable(row, column)) {
    column += 1;

    if (column == columnCount) {
    column = 0;
    row += 1;
    }

    if (row == rowCount) {
    row = 0;
    }

    // Back to where we started, get out.

    if (row == table.getSelectedRow()
    && column == table.getSelectedColumn()) {
    break;
    }
    }

    table.changeSelection(row, column, false, false);

    JFrame frame1 = new JFrame("MOUSELISTENER FRAME");
    Object rows[][] = { { "one", "ichi - \u4E00" },
    { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" },
    { "four", "shi - \u56DB" }, { "five", "go - \u4E94" },
    { "six", "roku - \u516D" }, { "seven", "shichi - \u4E03" },
    { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" },
    { "ten", "ju - \u5341" } };
    Object headers[] = { "English", "Japanese" };
    JTable table2= new JTable(rows,headers);
    frame1.getContentPane().add(table2, BorderLayout.CENTER);
    frame1.setSize(400, 400);
    frame1.setVisible(true);
    // frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
    }
    };
    table.getActionMap().put(im.get(tab), tabAction);
    table.setSurrendersFocusOnKeystroke(true);

    }

    public static void main(String[] args) {
    Test frame = new Test();
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    }

    }


    with regards,
    clarion

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  2. Limiting the capacity of a cell of JTable
    By rameshraj in forum Advanced Java
    Replies: 0
    Last Post: 03-24-2008, 02:20 PM
  3. Select specific cell
    By Echilon in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 07:47 AM
  4. Replies: 4
    Last Post: 05-19-2007, 11:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •