Problen in appearing  Jtable in JTextPAne ???

Hi. to all,
In thiscode i try to appear table in JTextPane .. There is a button "table" when you press on it the JDilog will appear in it you can specify the number of row and column to design the table ..... then when you press applay in JDilog the table should appear
There is my try but it has error can't adjust it please any one tell me the correct way :
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
public class Table extends JFrame {
    private JTextPane textPane=new JTextPane();
    private JButton tableButton=new JButton("Table");
    private JPanel mainPanel=new JPanel();
    public Table(){
        mainPanel.setLayout(new BorderLayout());
        mainPanel.add(tableButton,BorderLayout.NORTH);
        tableButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                   new TableTest().setVisible(true);
                   textPane.setText(new TableTest().myTable);    // This ie error but i can not the way to set table in textpane
        mainPanel.add(textPane,BorderLayout.CENTER);
        getContentPane().add(mainPanel);
    public static void main(String[]args){
        Table table=new Table();
        table.setDefaultCloseOperation(Table.EXIT_ON_CLOSE);
        table.setSize(new Dimension(500,250));
        table.setLocationRelativeTo(null);
        table.setVisible(true);
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionListener;
import java.util.Hashtable;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
public class TableTest extends JDialog {
    private JSpinner rowSpinner, colSpinner;
    private Box mainBox, rowSpinnerBox, colSpinnerBox;
    private JLabel rowLabel, columnLabel;
    private JTextField rowField, colField;
    private TitledBorder titledBorder;
    private JButton okButton,cancelButton;
    public TableModel myTable;
    private int[] row;
    private int[] col;
    public TableTest() {
        intializeSpinner();
        intializeBox();
        intializeLabel();
        intializeTextField();
        intializeButton();
        designView();
        row = (int[]) rowSpinner.getValue();
        col = (int[]) colSpinner.getValue();
        myTable = new TableModelTest(row, col);
        JTable table = new JTable(myTable);
        JScrollPane scrollPane = new JScrollPane(table);
        getContentPane().add(mainBox);
        getContentPane().add(scrollPane);
    private void intializeSpinner() {
        rowSpinner = new JSpinner();
        rowSpinner.setPreferredSize(new Dimension(100, 15));
        rowSpinner.setMaximumSize(new Dimension(100, 15));
        colSpinner = new JSpinner();
        colSpinner.setPreferredSize(new Dimension(100, 15));
        colSpinner.setMaximumSize(new Dimension(100, 15));
    private void intializeBox() {
        titledBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3), "Insert table");
        mainBox = Box.createVerticalBox();
        mainBox.setBorder(titledBorder);
        rowSpinnerBox = Box.createHorizontalBox();
        colSpinnerBox = Box.createHorizontalBox();
    private void intializeLabel() {
        rowLabel = new JLabel("Insert row       :");
        columnLabel = new JLabel("Insert column :");
    private void intializeTextField() {
        rowField = new JTextField();
        rowField.setPreferredSize(new Dimension(100, 15));
        rowField.setMaximumSize(new Dimension(100, 15));
        colField = new JTextField(10);
        colField.setPreferredSize(new Dimension(100, 15));
        colField.setMaximumSize(new Dimension(100, 15));
    public void intializeButton(){
        okButton=new JButton("ok");
        cancelButton=new JButton("cancel");
    public void okButtonAddActionListener(ActionListener listener){
        okButton.addActionListener(listener);
    private void designView() {
        rowSpinnerBox.add(rowLabel);
        rowSpinnerBox.add(Box.createHorizontalStrut(5));
        rowSpinnerBox.add(rowField);
        rowSpinnerBox.add(Box.createHorizontalStrut(5));
        rowSpinnerBox.add(rowSpinner);
        //   rowSpinnerPanel.add(Box.createHorizontalGlue());
        colSpinnerBox.add(columnLabel);
        colSpinnerBox.add(Box.createHorizontalStrut(5));
        colSpinnerBox.add(colField);
        colSpinnerBox.add(Box.createHorizontalStrut(5));
        colSpinnerBox.add(colSpinner);
        //  colSpinnerPanel.add(Box.createHorizontalGlue());
        mainBox.add(rowSpinnerBox);
        mainBox.add(Box.createVerticalStrut(5));
        mainBox.add(colSpinnerBox);
        mainBox.add(Box.createVerticalGlue());
    class TableModelTest extends AbstractTableModel {
        public Hashtable lookUp;
        public int rows;
        public int columns;
        public int[] columnNames;
        public TableModelTest(int[] rows, int[] colNames) {
            this.rows = rows.length;
            this.columns = colNames.length;
            lookUp = new Hashtable();
            // this.columnNames = new int[columns];
            //  System.arraycopy(colNames, 0, this.columnNames, 0, columns);
        public int getRowCount() {
            return rows;
        public int getColumnCount() {
            return columns;
        public Object getValueAt(int rowIndex, int columnIndex) {
            return lookUp.get(new Point(rowIndex, columnIndex));
}thanks in advance

In thiscode i try to appear table in JTextPane Basically you add the component throught the JTextPane model which is the document; the new style contain the table as an attribute and registered with StyleConstants
try this ( not tested)
StyleContext context = new StyleContext();
    StyledDocument document = new DefaultStyledDocument(context);
    Style tableStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
    TableModel model = new DefaultTableModel( new Object[]{"col1", "col2"}, 2);
    JTable table = new JTable(model);
    StyleConstants.setComponent(tableStyle, table);
    try {
      document.insertString(document.getLength(), "this will not show", tableStyle );
    } catch (BadLocationException badLocationException) {
      System.err.println("Oops");
    JTextPane textPane = new JTextPane(document);
    textPane.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textPane);Why you do not build an html page which contains the table and set the text on the JTextPane to this page( String); then add hyperlinkListener so that you can rebuild the html table upon an predefined different links inside the html table
Hope this could help. Please give me a shout in case you need further help
Regards,
Alan Mehio
London,UK

Similar Messages

  • BC4J: Split TableData to JTable and JTextPane - possible? - how

    Hi all,
    I got a table with some columns, but 2 of them can contain more than 1000 characters. So I want the content of these 2 columns displayed in 2 JTextpanes, which then contain always the content of theses to columns when a row is selected.
    My question now is:
    How can I get them into the JTextPanes and is there a chance/method to get the primary key of a row when the row which is selected?
    I also have to question how to hide a column, because I want to hide the primary key but only hide and how to change the header of the jTable.
    I tried:
    tableEmpView1.getColumn("Empno").setHeaderValue("Employee Number");
    tableEmpView1.getColumnModel( ).removeColumn(tableEmpView1.getColumn("Job"));
    But the don't work in my application!
    I can remove the colum with this call but then I also removed it from the tablemodel, so I have no chance to get the content of the "hiddeN" column after that and the oder method-call doesn't work, although there is no compiler error or runtime error there is no headerValue changed.
    Anyone any Idea about my question?
    Thanks
    Peter Zerwes

    Hi all,
    I got a table with some columns, but 2 of them can contain more than 1000 characters. So I want the content of these 2 columns displayed in 2 JTextpanes, which then contain always the content of theses to columns when a row is selected.
    My question now is:
    How can I get them into the JTextPanes and is there a chance/method to get the primary key of a row when the row which is selected?There are two questions here. One is how to display some attribute from a row in JTable in another control, such that only the current row value is displayed in the other control. You simply need to drop the other control in the UI editor and bind it to the same ViewObject and desired attribute. Framework will coordinate the passing of value from the current row into that attribute. See OTN sample "JClient Binding demo" - how it handles the display of Image control in a pane with JTable (Image for current Item from JTable is displayed in ImageControl). The sample is at:
    http://otn.oracle.com/sample_code/products/jdev/jclient/jclient_binding_demo.html
    The second question is how to get the primary key of the row which is selected.
    Call panelBinding.findIterBinding(<your iterator name>).getCurrentRow();
    I also have to question how to hide a column, because I want to hide the primary key but only hide and how to change the header of the jTable.
    I tried:
    tableEmpView1.getColumn("Empno").setHeaderValue("Employee Number");
    tableEmpView1.getColumnModel( ).removeColumn(tableEmpView1.getColumn("Job"));
    But the don't work in my application!
    I can remove the colum with this call but then I also removed it from the tablemodel, so I have no chance to get the content of the "hiddeN" column after that and the oder method-call doesn't work, although there is no compiler error or runtime error there is no headerValue changed.
    Anyone any Idea about my question?TO hide a column from display, you may either not select that column in the JTable binding or provide a control-hint "display=hide" in the ViewAttribute editor on the desired ViewObject attribute in your BC4J project.
    To change Table headers, etc see OTN how to at
    http://otn.oracle.com/products/jdev/howtos/JClient/jclient_jtable.html
    Thanks
    Peter Zerwes

  • Problem while reading JTable from JTextPane

    Hi,
    I am facing a bizarre problem. My JTextPane can contain rich text, image and table. While I am reading the tables from the JTextPane, I find that if there are more than one JTable, then the second table is returned first, then the first table.
    Still I have not found the exact pattern it returns when there are more than one table in the JTextPane, however I am getting the table in a different sequence than they were entered in the TextPane.
    Thanks in advance for the help.

    Hi,
    I am facing a bizarre problem. My JTextPane can contain rich text, image and table. While I am reading the tables from the JTextPane, I find that if there are more than one JTable, then the second table is returned first, then the first table.
    Still I have not found the exact pattern it returns when there are more than one table in the JTextPane, however I am getting the table in a different sequence than they were entered in the TextPane.
    Thanks in advance for the help.

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

  • JTable header problem plz help me

    hi
    i want to insert JTable in JTextPane but I have two problems
    i can't do this so any help plz
    1- i want to insert table with header and allow the user to edit (write) on the table header when running the
    program
    2- i want to insert table without header but i want to make the table column still resizable

    hi
    i want to insert JTable in JTextPane but I have two problems
    i can't do this so any help plz
    1- i want to insert table with header and allow the user to edit (write) on the table header when running the
    program
    2- i want to insert table without header but i want to make the table column still resizable

  • JTree clearSelection

    When JTree loses its focus, I want to changed the selected path to
    another color. The problem is, that it's not enough to just change the
    selected color.
    You have to clear the selection and than set the new colors, so the
    JTree doesn't containt information of selectedPaths...
    The problem is, it's not showing the changed color.
    Here's my getTreeCellRendererComponent code path below:
       public Component getTreeCellRendererComponent(final JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
          super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
          final DefaultMutableTreeNode storeNode = (DefaultMutableTreeNode) value;
          Object nodeObject = storeNode.getUserObject();
          Object[] objPath = storeNode.getUserObjectPath();
          String imagePath = getImagePath(nodeObject);
          if (imagePath != null) {
             try {
                Image image = AWTUtilities.getSystemImageResource(imagePath);
                if (image != null) {
                   setIcon(new ImageIcon(image));
                else {
                   if (Constants.DEBUG) {
                      System.err.println("StoreTreeCellRender::getTreeCellRendererComponent No image path found for \"" + imagePath + "\"");
             catch (java.io.IOException e) {
                if (Constants.DEBUG) {
                   e.printStackTrace();
          else {
             System.err.println("StoreTreeCellRender::getTreeCellRendererComponent No image path found for \"" + value + "\"");
          if (selected) {
             if (hasFocus) {
                setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
             else {
                // WHY IT'S ONLY CLEARING THE SELECTION?
                // DOESN'T SET THE FOREGROUND/BACKGROUND.
                // IF COMMENT tree.clearSelection.. IT SETS THE COLORS?
                tree.clearSelection();
                setForeground(UIManager.getColor("Tree.textForeground"));
                setBackgroundSelectionColor(UIManager.getColor("Panel.background"));
          return this;
       }

    Someone please help.
    Want the tree selected node to be cleared and also it's background
    color changed when tree loses focus. The problem is if I twink the
    tree cell renderer, I can't use clearSelection as I believe it does
    a callback to renderer again and never get the desired result.
    Either the renderer background was changed, and changed back to unselected situtation or all the renderer node background is changing...
    Am going around in circles, frustrating!!?
    Trying to now have my JTree class implement focusListener and overwrite
    focusGained and focusLost but need help to getting the tree node component but believe it can only be access in the treeCellRenderer.
    Again, going around in circle...
    In my JTree class:
       public class myTree extends JTree implements FocusListener {
          public myTree() {
             addFocusListener(this);
             // Only want single selection...
             getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
       public void focusGained(FocusEvent e) {
          if (!getSelectionModel().isSelectionEmpty()) {
             // Clear the last selected node background in focusLost
             // How to get the TreePath component?
       public void focusLost(FocusEvent e) {
          Component oppositeComponent = e.getOppositeComponent();
          // Want if lost focus and user clicks on JTable or JTextPane
          // to handle the focus lost part...
          if (oppositeComponent instanceof JTable ||
              oppositeComponent instanceof JTextPane) {
             DefaultMutableTreeNode node = (DefaultMutableTreeNode) getLastSelectedPathComponent();
             TreePath selectedTreePath = new TreePath(node.getPath());
             boolean nodeSelected = getSelectionModel().isPathSelected(selectedTreePath);
             JComponent c = (JComponent)
                 getCellRenderer().
                 getTreeCellRendererComponent(this, node, nodeSelected,
                                              isExpanded(selectedTreePath),
                                              node.isLeaf(),
                                              getRowForPath(selectedTreePath),
                                             ((DefaultTreeCellRenderer)
    getCellRenderer()).isFocusable());
             // Only want to change one node component
             // It's changing all the nodes!!
             c.setForeground(UIManager.getColor("Tree.textForeground"));
             c.setBackground(UIManager.getColor("Panel.background"));
             c.setBorder(javax.swing.BorderFactory.createEtchedBorder());
             clearSelection();
             repaint();

  • Background, Foreground of JComboBox

    Hi,
    I'm having trouble formatting. I have an array of Strings in a JComboBox in a BasicComboPopup appearing in a JTextPane. The popup works fine, but I'd like to set the background and foreground colors of the popup to different colors from their defaults.
    Currently, I'm trying this:
    String [] myDisplayItems = { "Riker", "LaForge", "Picard" };
    JComboBox box = new JComboBox(myDisplayItems);
    BasicComboPopup popup = new BasicComboPopup(box);
    box.setBackground(Color.YELLOW);
    box.setForeground(Color.RED);
    popup.setBackground(Color.YELLOW);
    popup.setForeground(Color.RED);
    box.setVisible(true);
    popup.show(this, 100, 100);
    After setting color, if I print getBackground().toString() or getForeground().toString() I get the correct RGB values. However, when the box pops up, the colors I set do not appear.
    Am I doing something wrong? What's the correct way to do this?
    All help appreciated. Cheers.

    Try:
    UIManager.put("ComboBox.background",Color.YELLOW);
    UIManager.put("ComboBox.foreground",Color.RED);
    before you create any combobox.
    ;o)
    V.V.

  • Combo Box in a JTable not appearing

    Hi Swing,
    I have a snippet of code that I took from the Swing guide for JTables that adds a JComboBox into the 3rd column in the table. However, the ComboBox doesnt appear?
    Can anyone see what is going wrong? Code is below:- I can post more if needed:-
         public void addTable() {
              tableModel = new MyTableModel(rows,columns);
              relationTable = new JTable(tableModel);
           //Set up the editor for the sport cells.
            TableColumn sportColumn = table.getColumnModel().getColumn(2);                                              
            JComboBox allStaff = new JComboBox();
            allStaff.addItem("Snowboarding");
            allStaff.addItem("Rowing");
            allStaff.addItem("Knitting");
            allStaff.addItem("Speed reading");
            allStaff.addItem("Pool");
            allStaff.addItem("None of the above");
            sportColumn.setCellEditor(new DefaultCellEditor(allStaff));
              // set so only one row can be selected at once
              relationTable.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
              relationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              // add to pane:-
              JScrollPane scrollPane3 = new JScrollPane(relationTable);
              scrollPane3.setBounds(X,Y,Z,W);
              getContentPane().add(scrollPane3 );
         }Cheers

    hi
    look I will give u a simple code I created based on your combo box
    enjoy (:
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    public class TablCo extends JPanel {
    static JFrame frame;
    JTable table;
    DefaultTableModel tm;
    public TablCo() {
    super(new BorderLayout());
    JPanel leftPanel = createVerticalBoxPanel();
    //Create a table model.
    tm = new DefaultTableModel();
    tm.addColumn("Column 0");
    tm.addColumn("Column 1");
    tm.addColumn("Column 2");
    tm.addColumn("Column 3");
    tm.addRow(new String[]{"01", "02", "03", "Snowboarding"});
    tm.addRow(new String[]{"04 ", "05", "06", "Snowboarding"});
    tm.addRow(new String[]{"07", "08", "09", "Snowboarding"});
    tm.addRow(new String[]{"10", "11", "12", "Snowboarding"});
    //Use the table model to create a table.
    table = new JTable(tm);
              //insert a combo box in table
              TableColumn sportColumn = table.getColumnModel().getColumn(3);
              JComboBox allStaff = new JComboBox();
                   allStaff.addItem("Snowboarding");
                   allStaff.addItem("Rowing");
                   allStaff.addItem("Knitting");
                   allStaff.addItem("Speed reading");
                   allStaff.addItem("Pool");
                   allStaff.addItem("None of the above");
              //DefaultCellEditor dce = new DefaultCellEditor(allStaff);
              sportColumn.setCellEditor(new DefaultCellEditor(allStaff));
              JScrollPane tableView = new JScrollPane(table);
    tableView.setPreferredSize(new Dimension(300, 100));
              leftPanel.add(createPanelForComponent(tableView, "JTable"));
              JFrame.setDefaultLookAndFeelDecorated(true);
              //Create and set up the window.
              frame = new JFrame("BasicDnD");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //Create and set up the content pane.
              frame.setContentPane(leftPanel);
              //Display the window.
              frame.pack();
              frame.setVisible(true);
              protected JPanel createVerticalBoxPanel() {
              JPanel p = new JPanel();
              p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
              p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
              return p;
              public JPanel createPanelForComponent(JComponent comp,
              String title) {
              JPanel panel = new JPanel(new BorderLayout());
              panel.add(comp, BorderLayout.CENTER);
              if (title != null) {
              panel.setBorder(BorderFactory.createTitledBorder(title));
              return panel;
    public static void main(String[] args) {
         new TablCo();
    }

  • JTable in JScrollpane doesn't appear

    Hi,
    Maybe, it's already asked 1000 times on this forum but I didn't found the right solution.
    My problem :
    I've created a JPanel with a JScrollpane.
    When I create the JScrollpane immediately with a JTable it works fine, the JTable appears.
    Now I try to add the JTable dynamically to the JScrollpane.
    The JTable doesn't appear.
    I've tried already the repaint, validate methods but that changes nothing.
    Can anyone tell me how I can solve my problem ?
    Thanx in advance,
    Piet

    I trust you are adding it like this:
    myJScrollPane.getViewport().add(myJTable);
    not like this:
    myJScrollPane.add(myJTable);

  • JTable on JPanel on JFrame, not appearing

    I can't see the JTable that I was expecting to between the two labels, any ideas why?
    public class Workout extends JFrame {
            final String[] exercisesDoneColumnNames = {"Exercise", "# Sets", "Set 1", "Set 2", "Set 3", "Set 4", "Set 5", "Set 6", "Set 7", "Set 8", "Set 9", "Set 10"};
            private ExercisesDoneTable myModel = new ExercisesDoneTable exercisesDoneColumnNames,0);
            private JTable table = new JTable(myModel);
            public Workout() {
                super.setTitle("Workout");
                buildExerciseDoneTable();
                Toolkit tk = Toolkit.getDefaultToolkit();
                Dimension d = new Dimension();
                d = tk.getScreenSize();
                setSize((int)d.getWidth(), (int)d.getHeight());
                setLocation(0,0);
                super.setName("Workout");
                addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent evt) {   
                        System.exit(0);
                JPanel p = new JPanel();
                p.setBackground(java.awt.Color.white);
                p.add(new JLabel("left of"));
                p.add(table);
                p.add(new JLabel("right of"));
                getContentPane().add(p);
                setVisible(true);
        //helper method just splits the code to make it more readable
        private void buildExerciseDoneTable(){
            table.setPreferredScrollableViewportSize(new Dimension(500,100));
            myModel.addTableModelListener(myModel);
            table.setVisible(true);
        }

    JPanel has a default FlowLayout.
    I think you table is there, but is not displaying anything as you have specified 0 rows when creating your table model. Change that number to 1 and you will see it appear.

  • JTable appears on maximizing Frame

    The JTable does not appear till I resize the frame.
    Relevant Points:
    1. I am using a TableModel which extends AbstractTableMode to fetch the data for the JTable.
    2. The JTable is being added to the JScrollPane. And the JScrollPane is being added on the JPanel.
    I have worked on it for a quite a while and cannot figure out why should the JTable be displayed only if the window resizes.

    hi,
    it looks like a repaint problem.
    did you call validate() or repaint() or both on the JFrame after adding the jtable?

  • Add scroll to JTextPane in JTable

    Hello,
    I create JTable that her cells is JTextPane.
    The problem is that i need that the JTextPane will have scroll.
    I tried to add but the scroll isn't show.
    Advices with examples are welcome
    Thanks in advance
    Shimon

    hi
    try compile and run the code and watch behaivour, hope this is will help u...
    cheers and good luck
    gkr
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JTableExample extends JFrame
    JScrollPane jScrollPane1 = new JScrollPane();
    JTextPaneCell JTPC = new JTextPaneCell();
    DefaultTableModel dtm = new DefaultTableModel(new Object[]{"Col1", "Col2",
    "JTextPane", "Col4"}, 10);
    String v = "Hello, \nI create JTable that her cells is JTextPane.\n" +
    "The problem is that i need that the JTextPane will have scroll.\n"
    + "I tried to add but the scroll isn't show.\n" +
    "Advices with examples are welcome.\n\nThanks in advance\n\n" +
    "Shimon.";
    JTable jTable1 = new JTable(dtm)
    public int getRowHeight()
    return super.getRowHeight() * 4;
    public TableCellRenderer getCellRenderer(int row, int column)
    if(super.convertColumnIndexToModel(column) == 2)
    return JTPC;
    return super.getCellRenderer(row, column);
    public TableCellEditor getCellEditor(int row, int column)
    if(super.convertColumnIndexToModel(column) == 2)
    return JTPC;
    return super.getCellEditor(row, column);
    public JTableExample()
    try
    jbInit();
    for(int i = 0; i < dtm.getRowCount(); i++)
    dtm.setValueAt("\n" + i + v, i, 2);
    pack();
    catch(Exception e)
    e.printStackTrace();
    public static void main(String[] args)
    JTableExample JTableExample1 = new JTableExample();
    JTableExample1.show();
    private void jbInit() throws Exception
    jScrollPane1.getViewport().add(jTable1);
    getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(JTPC.spane);
    SwingUtilities.updateComponentTreeUI(this);
    class JTextPaneCell extends AbstractCellEditor implements
    TableCellRenderer, TableCellEditor
    JScrollPane spane;
    JTextPane tpane;
    Border noFocusBorder;
    public JTextPaneCell()
    super();
    noFocusBorder = new EmptyBorder(1, 1, 1, 1);
    spane = new JScrollPane();
    tpane = new JTextPane();
    spane.getViewport().add(tpane);
    public Component getTableCellEditorComponent(JTable table, Object value,
    boolean isSelected,
    int row, int column)
    return spane;
    public Object getCellEditorValue()
    return tpane.getText();
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column)
    if(isSelected)
    tpane.setForeground(table.getSelectionForeground());
    tpane.setBackground(table.getSelectionBackground());
    else
    tpane.setForeground(table.getForeground());
    tpane.setBackground(table.getBackground());
    tpane.setFont(table.getFont());
    if(hasFocus)
    spane.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
    if(table.isCellEditable(row, column))
    tpane.setForeground(UIManager.getColor("Table.focusCellForeground") );
    tpane.setBackground(UIManager.getColor("Table.focusCellBackground") );
    else
    spane.setBorder(noFocusBorder);
    if(value == null)
    value = "";
    tpane.setText((String)value);
    return spane;
    }

  • JTable JComboBox appears a few bits left than the cell

    Hi,
    I 'm using the following code to display a JComboBox in the 4th column of my JTable.
    TableColumn tableColumn = table.getColumnModel().getColumn(3);
    String[] values = {"", "ASC", "DESC"};
    tableColumn.setCellEditor(new DefaultCellEditor(new JComboBox(values)));
    JScrollPane scrollPane = new JScrollPane(table);
    mainContainer.setLayout(new BorderLayout());
    mainContainer.add(BorderLayout.CENTER, scrollPane);
    The strange thing is that when I click on the combo box to select a value, the combo box appears a few pixels on the left of the cell that I edit, and not exaclty under it. Has anybody else encountered such a problem?
    | ASC | <---------- table cell
    | |
    | ASC | <---------- combo box
    | DESC |
    Thanks in advance.
    John.

    Hi,
    I 'm using the following code to display a JComboBox in the 4th column of my JTable.
    TableColumn tableColumn = table.getColumnModel().getColumn(3);
    String[] values = {"", "ASC", "DESC"};
    tableColumn.setCellEditor(new DefaultCellEditor(new JComboBox(values)));
    JScrollPane scrollPane = new JScrollPane(table);
    mainContainer.setLayout(new BorderLayout());
    mainContainer.add(BorderLayout.CENTER, scrollPane);
    [/code/
    The strange thing is that when I click on the combo box to select a value, the combo box appears a few pixels on the left of the cell that I edit, and not exaclty under it. Has anybody else encountered such a problem?
    | ASC | <---------- table cell
    | |
    | ASC | <---------- combo box
    | DESC |
    Thanks in advance.
    John.

  • JTable edited data doesn't appear in the same time

    Hi
    i have aserious problem JTable edited data doesn't appear in the same time imust tom minimize the frame and maximize it to see the table modified what is the reason?

    Quit multi-posting the same question every time. You asked this same question 3 hours ago:
    http://forum.java.sun.com/thread.jspa?threadID=729894
    The last time you posted the same question within two minutes of one another:
    http://forum.java.sun.com/thread.jspa?threadID=729202
    http://forum.java.sun.com/thread.jspa?threadID=729200
    Not only that, you never bother to reply to your postings to indicate whether the advice given was helpfully or not. This is commonly known as thanking people for the time spent helping your.
    Learn to use the forum correctly or you will be on your own in the future.

  • Appearing the added JTable's cell JComboBox at running the Class

    During the time of employing the JTable,arising the problem of how to appear the added JTable's cell JComboBox at loading the class..Can you aid me plz to resolve this bug...If u know answer,plz forward the resolution..

    Sorry, I don't understand the question so I'll just point you to the Swing tutorial on "How to Use Tables" which has a working example of using a combo box in a table:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

Maybe you are looking for

  • Qosmio G10-100: Installing second HDD & obtaining mounting bracket

    I'd like to install a second hard drive. Any instructions or general tips on how to do so would be greatly appreciated. I'm looking at purchasing a HITACHI T7K500 Desktar 2.5" - 320 GB Interface: SATA 3.0 GB/s serial & ATA Ultra 133 parallel. Is this

  • Recommendations - Oracle RAC 10g on Solaris 10 Containers Logical/Local..

    Dear Oracle Experts et all I have a couple of questions for Oracle 10g RAC implementation on Solaris and seek your advice. we are attempting to implement oracle 10g RAC on Solaris OS and SPARC Platform. 1 We are wondering if Oracle 10g RAC could be i

  • Backing up pictures on my iPhotos

    Hi! I have a question two questions that I'm hoping you'll be able to help me with. *My problem:* I have over 7,000 photos on my iPhotos and it's making my computer move very slow, so I need to take the majority off and just put it on my external har

  • Change Expense Report in FITV_POWL_TRIPS Application

    Hi, In my workflow, i would like to call the change expense report in FITV_POWL_TRIPS application. In FITV_POWL_TRIPS Application, it shows all the expense reports and if user wants to Change, then need to press the CHANGE button which shows in the A

  • Execute multiple dml statements concurrently.

    Hi all, I have a requirement to execute multiple dml statements at the same time. I tried to achieve this using dbms_job, but failed. I scheduled 3 dbms_job at the same time. Each job has a bulk insert statement, inserting into a single target table.