table row height


I have a JTable with a comboBox as a cell editor.

This works fine but looks a little bad.

The comboBox needs to be editable. When the user clicks on a cloumn in the table whose editor is the combo box, it appears to be not tall enough.

Here are some code snippets to show you what I mean:
[code]
// create the table
final JTable table = new JTable(new MyTableModel( ));

// create the combo box
JComboBox acctsComboBox = new JComboBox(theAccounts);
acctsComboBox.setEditable( true );

// set the editor
TableColumn descColumn = table.getColumnModel().getColumn(2);
descColumn.setCellEditor(new DefaultCellEditor( acctsComboBox ));

// adjust the width of the column
int preferredWidth = getWidestEntry( acctsComboBox,
table.getFontMetrics(table.getFont()), table.getGraphics());

if (preferredWidth >= 0)
descColumn.setPreferredWidth( preferredWidth );
[\code]
Posted On: Tuesday 23rd of October 2012 11:08:33 PM Total Views:  86
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




jtable help

In jtable when a value is being edited a border is highlighted arround the cell. But once the cursor is out of focus for instance to another component on the form, the border on the cell is still highlighted and the value that was entered on the cell doesnt get saved to the database. Is there a way to solve this issue.
VIEWS ON THIS POST

125

Posted on:

Monday 22nd October 2012
View Replies!

jtable help

In jtable when a value is being edited a border is highlighted arround the cell. But once the cursor is out of focus for instance to another component on the form, the border on the cell is still highlighted and the value that was entered on the cell doesnt get saved to the database. Is there a way to solve this issue.
VIEWS ON THIS POST

119

Posted on:

Monday 22nd October 2012
View Replies!

jtable rendering problem

I have problem in displaying the default AND values in the combo boxes in the table. The table in its empty state, that is when it is contructed and before the user has a chance to make any changes, a row with no data and 2 columns is created. The table looks like: (empty)|(empty) When the user hits the button once, the new row is added at position 0 in the table and the row that was created first without the user hitting the button moves down. Now the table looks like : (empty)|(some value) (empty)|(empty) When the user hits the button the second time, the new row is added at the last but one row and the table looks like : (empty)|(some value) AND|(some value) (empty)|(empty) When the user hits the button the third time,the new row is added at the last but one row and the table looks like : (empty)|(some value) AND|(some value) AND|(some value) (empty)|(empty) When the user hits the button the fourth time,the new row is added at the last but one row and the table looks like : (empty)|(some value) AND|(some value) AND|(some value) AND|(some value) (empty)|(empty) Addtional rows can be added thus expanding the table.
VIEWS ON THIS POST

120

Posted on:

Monday 22nd October 2012
View Replies!

SWT set image on table header, change font

I called TableColumn.setImage() which placed the image to the left of the table column header. But all rows in this column shift to the right leaving en empty space about the size of the icon. Is there a way to keep the content from moving right 2nd question is can I control where to image sit, to the left or right of the table header string 3rd question is if there's a way to set the font of a specific table header Table class has setFont() method, but not in the TableColumn class.
VIEWS ON THIS POST

90

Posted on:

Monday 22nd October 2012
View Replies!

JTable - editable columns

everybody, Can somebody tell me, how to use this code to allow or to disable editing different columns, if it is possible (this code is taken from http://www.javaalmanac.com/egs/javax.swing.table/NoEdit.html ) JTable table1 = new JTable() { public boolean isCellEditable(int rowIndex, int vColIndex) { return false; } }; OK, I already found the answer, I think. confModel = new DefaultTableModel(new Vector(), new Vector()); JTable confTable = new JTable(confModel){ public boolean isCellEditable(int rowIndex, int colIndex) { if (colIndex < 2) { return false; } else { return true; } } }; [ May 12, 2006: Message edited by: Bodhi Karam ]
VIEWS ON THIS POST

31

Posted on:

Monday 22nd October 2012
View Replies!

Editable combobox events

Hi , This particular problem has been bothering me for some time now.I have a simple application which consists of an editable combobox,a "send" button,a checkbox("echo") and a non editable textarea where information is logged. It works like this...a command is entered in the combo(which is also stored for later use in the combo),if echo is ticked then cmd and response are displayed in the textarea,else only response is displayed.To send the command,user can either click "send" button or press enter. I have used actionListener for the combo(not for the send button) since it fires a comboboxEdited and comboboxChanged whenever a change is done.This is doing the required task.But the problem occurs when there is no change in the combo(like if you just choose a previous command) and the user decides to click "send".Because there is no listener for send,nothing happens.But if i add a listener for send,then clicking of send results in data being logged twice(one for comboboxEdited and the other for send).I have also tried to use a keylistener for the combo,but tht also does not work.can someone throw some light on ths problem(sorry its been lengthy!)...
VIEWS ON THIS POST

69

Posted on:

Tuesday 23rd October 2012
View Replies!

DND from one table cell to another in the same table

I've implemented dnd from a jlist to a jtable. Now I'd like to be able to drag from one cell in the table and drop into another cell in the same table. My issue is that all of the events (export and import) seem to be triggered as soon as the mouse button is pressed on a table cell, and then nothing happens when the mouse button is released over the new cell. Does anyone have experience in DND within the same JTable ms
VIEWS ON THIS POST

69

Posted on:

Tuesday 23rd October 2012
View Replies!

Jtable sorting; problem with getValueAt

Hi , I have implimeneted a sorting JTree (with a TableSorter). Problem is when the user clicks on the column, say length, the sorting is incorrect. (it sorts it as if it's a String; same goes to the sort by dueDate) I understand that the sorting is according to the object's type. the due date is a String in the example below but when converting to Date, the result is: Wed Aug 10 00:00:00 PDT 2005) (!) anyone knows how to correct this
VIEWS ON THIS POST

87

Posted on:

Tuesday 23rd October 2012
View Replies!

adding rows to table dynamically

! i am getting records from a database table and dynamically want to add them to table. how could i do this please help me.
VIEWS ON THIS POST

46

Posted on:

Tuesday 23rd October 2012
View Replies!

Dynamic tables

Howdy. I'm currently working on GUI app and am having some difficulties with tables. On my frame I've got essentially two panels, the criteria panel (crP) and the results panel (reP). What I would like to do enter search criteria in the crP and have the results displayed in the reP. When the user fills in the relevant information in the crP and then hits the "search" button, the table in the reP will then get filled with matching results from the database. So far, I'm good for creating the panels and getting the results from the search. My problem comes with trying to have the table change to recieve the information. I'm posting the class as it stands at the moment. It's a bit messy since I've been fiddling with trying to get this to work. package frames; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; import utilities.Convert; import utilities.MyConstants; import utilities.dataBase.DataGateway; import utilities.dataBase.SQLBuilder; public class MainMenu extends JFrame { private static final long serialVersionUID = 1L; JPanel cPane = new JPanel(new FlowLayout()); JTabbedPane tabbedPane = new JTabbedPane(); JTable staffTable = new JTable(); public MainMenu(){ super("MainMenu"); createAndShowGUI(); } private void createAndShowGUI() { setContentPane(cPane); tabbedPane.addTab("Staff", makeStaffPanel()); cPane.add(tabbedPane); pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } private JComponent makeStaffPanel() { final JPanel panel = new JPanel(new FlowLayout()); JLabel lPosition = new JLabel("Position:"); JLabel lFName = new JLabel("First name:"); JLabel lLName = new JLabel("Last name:"); JLabel lProgram = new JLabel("Program:"); JLabel lSDate = new JLabel("Start date"); JLabel lEDate = new JLabel("End date"); JButton search = new JButton("search"); //These have to be final so we can access them in the inner class final JComboBox cbPosition = new JComboBox(MyConstants.POSITION_OPTNS); final JTextField tFName = new JTextField(); tFName.setColumns(MyConstants.TEXT_FIELD_SIZE_SMALL); final JTextField tLName = new JTextField(); tLName.setColumns(MyConstants.TEXT_FIELD_SIZE_MEDIUM); final JTextField tProgram = new JTextField(); tProgram.setColumns(MyConstants.TEXT_FIELD_SIZE_MEDIUM); final JTextField tSDate = new JTextField(); tSDate.setColumns(MyConstants.TEXT_FIELD_SIZE_SMALL); final JTextField tEDate = new JTextField(); tEDate.setColumns(MyConstants.TEXT_FIELD_SIZE_SMALL); String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; Object[][] data = { {"Jake", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)} }; staffTable = new JTable(data, columnNames); panel.add(staffTable); panel.add(staffTable); /* panel.add(lPosition); panel.add(cbPosition); panel.add(lFName); panel.add(tFName); panel.add(lLName); panel.add(tLName); panel.add(lProgram); panel.add(tProgram); panel.add(lSDate); panel.add(tSDate); panel.add(lEDate); panel.add(tEDate); */ tFName.setText("Neil"); panel.add(search); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SQLBuilder sb = new SQLBuilder(); sb.addFrom(MyConstants.TABLE_STAFF); sb.addFrom(MyConstants.TABLE_TERM); sb.addWhere(MyConstants.FIELD_POSITION, cbPosition.getSelectedItem()); sb.addWhere(MyConstants.FIELD_FIRST_NAME, tFName.getText()); sb.addWhere(MyConstants.FIELD_LAST_NAME, tLName.getText()); sb.addWhere(MyConstants.FIELD_START_DATE, Convert.toDate(tSDate.getText()), ">="); sb.addWhere(MyConstants.FIELD_END_DATE, Convert.toDate(tEDate.getText()), "
VIEWS ON THIS POST

32

Posted on:

Tuesday 23rd October 2012
View Replies!

jtable right mouse click

hi! how can i set a selection with right mouse click in jtable it only works with left mouse clicks. my table has single_selection mode. thx martin
VIEWS ON THIS POST

145

Posted on:

Tuesday 23rd October 2012
View Replies!

Multiple table records in jtextfields

Hi all! Is it possible to have multiple table records vertically aligned, displayed in jtextfields and contained in a jpanel It looks something like a jtable in which multiple records are displayed one-by-one vertically but I want to control the spacing, position and add some data which are not fields in the table.
VIEWS ON THIS POST

73

Posted on:

Tuesday 23rd October 2012
View Replies!

Border on XP table header

I have a JTable with five columns. On the first two columns, I have made custom renderers to show a picture in the table header. The rest of the columns are normal. Please could someone tell me how to get the border that is applied to these normal columns so that I can apply the border to the custom headers. Many
VIEWS ON THIS POST

81

Posted on:

Tuesday 23rd October 2012
View Replies!

How to retrieve a specific cell in a table using SWT/JFace ?

Hi flks, Im totally newbie in SWT/JFace so my question may be so trivial for you. With an org.eclipse.swt.widgets.Table how can i access an specific cell of the table i.e: Row 3, Column 4. I can create a TableColumn or a TableItem giving a Table but is there any way to access a cell, givin a row and a column
VIEWS ON THIS POST

105

Posted on:

Tuesday 23rd October 2012
View Replies!

Mouselistner not working for a table object

Hi all, I have a JTable object called VTable present in the swing package. For this JTable, none of the listeners gets executed. VTable m_table = new VTable(rowData,colNames,false); m_table.addMouseListener(new java.awt.event.MouseListener(){ public void mouseClicked(MouseEvent e) { System.out.println("TEST!!!"); }
VIEWS ON THIS POST

76

Posted on:

Tuesday 23rd October 2012
View Replies!

How do i add label/textbox to a jtable

Hi all, Can anybody help me in this regard. I have a JTable with n number of rows. I want to implement a key search functionality on the table in such a way that after selecting a column and when i type a character, the character typed should be displayed in a small textbox on the table. (Similar to JBuilder - projects window, wherein when u keyin a character, a small yellow color label is visible displaying the different characters we typed in). How do i do the same in a jtable. Please help me in this regarsd as early aspossible
VIEWS ON THIS POST

112

Posted on:

Tuesday 23rd October 2012
View Replies!

Double JList for Selection Panel with editable fields

I'm not entirely sure how to describe this, but the widget should allow users to set up how they want a table to look. There is a list of available columns, and they have to choose which are visible, and of those that are visible they set how wide the column is, and a number indicating sort order. Sooooo.... I have been tasked to create two JList boxes, one for NOT visible columns and one for visible columsn. In between would be the "" buttons you often see that allow you to move the items back and forth from one list to another. In the "visible" JList, each item should ALSO have editable fields for entering the width & sort order. The not-visible JList should not show those fields. My questions are: 1. What do you call that thing when there are two JLists & the "" buttons in between That might make my search easier... 2. Can I do this with JLists...or do I need to try to implement this with two tiny tables (And just make it look like JLists) Any suggestions on where to start\t See silly image I made in Paint below: THANK YOU!!!
VIEWS ON THIS POST

88

Posted on:

Tuesday 23rd October 2012
View Replies!

jtable and the scrollbar

Has anyone ever programitcally changed their horizontal scrollbar I'm using a JTable in a scrollPane and I need to take three simple steps: 1. get the current position of the horizontal scroll bar 2. recreate the table with new data (not a problem) 3. reposition the scrollbar on the new table to the same position as the old table Can anyone give me an idea how to get the horizontal scrollbar position I tried this approach but haven't had much luck: scrollPane.remove( oldTable ); Point p = scrollPane.getViewport().getViewPosition(); scrollPane.setViewportView( newTable ); scrollPane.getViewport().setViewPosition(p);
VIEWS ON THIS POST

112

Posted on:

Tuesday 23rd October 2012
View Replies!

Jtable boolean checkboxes

I have a column in a Jtable which is boolen. I have a verify button that take you to a new screen I want to display just the rows that have a check in the box (boolean = true). My jtable data is in a vector.
VIEWS ON THIS POST

85

Posted on:

Tuesday 23rd October 2012
View Replies!

import an access table into a JList

I import an access table into a TextArea with a JScrollpane and I need some help to select multiple items using the control button. Please provide some insights.
VIEWS ON THIS POST

83

Posted on:

Tuesday 23rd October 2012
View Replies!