Adding A Column into a JTable
Hi
I have a JTable with two soccer teams in. What i want to do is to add in a column between them that just says "VS". I ahev to do this when the user clicks a button as the table is constructed from details stored in a MySQL database.
Can anyone give me any help?
Jason
the DefaultTableModel supports an addColumn() method, so:
a) create your table and TableModel
b) add a column to the end of the DefaultTableModel
Now the TableColumnModel controls the order in which the columns are painted, so
a) get the TableColumnModel from the table
b) move the colum to the center
Similar Messages
-
How can I add new row/column into existing jTable?
Hi add!
Can you help me how can I add new row/column into existing jTable?
Tnx in adv!e.g
Create two buttons inside the Table ( "Add New Row" ) and ("Add new Column")
their handlers are:
add new row:
//i supose u already have
DefaultTabelModel tablemodel = new DefaultTableModel(rowdata, columnNames);
//and
JTabel jtable = new JTable(tablemodel);
// Handler (row)
jbtAddRow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(jtable.getSelectedRow() >= 0 )
tablemodel.insertRow(jtable.getSelectedRow(), new java.util.Vector());
else
tablemodel.addRow(new java.util.Vector());
});to add new columns its the same but inside actionPerformed method:
ask for e.g "Whats the name for the new column"
then,
tablemodel.addColumn(nameOfColumn, new java.util.Vector()); Joao
Message was edited by:
Java__Estudante -
How to insert rows & columns into a jTable???
helloo there...
How to insert rows & columns into a jtable???
your reply is greatly appreciated....
-=samer=-Yes!thanks...
But what i want is how to set the number of rows and the number of columns...and i don't know how to setColumns and rows....any idea?
the user will input number of rows and columns in a jtextfield....
Please rply... -
Adding a column into existing index
Can I add a column into existing index?
or do I need to drop the index and recreate one?
Thanks.but there is no way to add a column to an existing table10:43:24 TEST.SQL>create table test10:43:28 2 (
10:43:29 3 a number
10:43:32 4 )
10:43:34 5 tablespace tools
10:43:36 6 ;
Table created.
Elapsed: 00:00:00.06
10:43:38 TEST.SQL>alter table test add
10:43:44 2 b date;
Table altered.
Elapsed: 00:00:00.68
10:43:48 TEST.SQL>desc test
Name Null? Type
A NUMBER
B DATE
10:43:51 TEST.SQL>drop table test;
Table dropped.Indeed there is.Yoann. -
Adding a column into the assets list view?
I am trying to find a way to add a column into the assets list view.
At the moment it has... Title, Metadata Set, Image Size, Duration, Size, Status etc...
I would like to add another metadata field into the list and cannot find anywhere to do it. For example, add the 'Reel' metadata field into the list.
Anyone have any ideas?
Thanks.1. Log into Final Cut Server as the Admin.
2. Open the Advanced Administration window from the java client.
3. Search for the Metadata Group name "List"
Note this search will return approximately 29 items, but you'll want to modify the one
with the Metadata Group ID "ASSETLISTVIEW"
4. Add the fields to that group that you want.
5. To have these field show up either create New Workspace or logout and login.
Hope this helps.
Nicholas Stokes
XPlatform Consulting
[email protected] -
I have a simple gui where I query a database and return a result set in a JTable using a table model. I would like to be able to add a new column with checkboxes as the first column in the table. I've seen examples using checkboxes with boolen data from the database, but this column is not being returned from the database it is a new added column.
The first task is to add the column and I am struggling with this. My code is below.
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class DatabaseTest extends JFrame {
private QueryTableModel qtm;
public DatabaseTest()
super("JTable Test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(350, 200);
qtm = new QueryTableModel();
JTable table = new JTable(qtm);
JScrollPane scrollpane = new JScrollPane(table);
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3, 2));
p1.add(new JLabel("Click here to Query the DB: "));
JButton jb = new JButton("Search");
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
qtm.Query();
p1.add(jb);
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(scrollpane, BorderLayout.CENTER);
public static void main(String args[]) {
DatabaseTest tt = new DatabaseTest();
tt.setVisible(true);
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
class QueryTableModel extends AbstractTableModel {
Vector cache;
private int colCount;
private String[] headers;
Statement statement;
private static Connection conn = null;
public QueryTableModel() {
cache = new Vector();
public String getColumnName(int i) {
return headers;
public int getColumnCount() {
return colCount;
public int getRowCount() {
return cache.size();
public Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];
public void Query() {
cache = new Vector();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:*****","******","*******");
statement = conn.createStatement();
ResultSet rs = statement.executeQuery("Select username from dba_users where rownum < 6");
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();
// Now we must rebuild the headers array with the new column names
headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = meta.getColumnName(h);
while (rs.next()) {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
cache.addElement(record);
fireTableChanged(null);
// Add column code here?
} catch (Exception e) {
cache = new Vector(); // blank it out and keep going.
e.printStackTrace();
}Not sure how to add the column. I've tried a few variations of the following code with no luck:TableColumn tc = new TableColumn(0, 120);
tc.setHeaerValue("Name");
table.getColumnModel().addColumn(tc);Any help would be appreciated.The first task is to add the column Well, I like the suggestions from the link given in the above posting :-) It shows you how to dynamically alter the TableModel after its initial creation, and is probably the best generic solution.
But, just so you understand better how a TableModel works I"ll just put another thought in your mind. Maybe in this case you just create the TableModel correctly the first time so you don't need to do a dynamic change. The TableModel doesn't know where the data came from. It doesn't care that it came from a ResultSet. All it knows it that you have data in an array. So whats to prevent you from hard coding the first column to contain Boolean data?
{code}headers = new String[colCount+1];
headers[0] = "Boolean Column";
for (int h = 1; h <= colCount; h++)
headers[h] = meta.getColumnName(h);
while (rs.next())
String[] record = new String[colCount+1];
record[0] = new Boolean.FALSE;
for (int i = 1; i <= colCount; i++)
record[i] = rs.getString(i);
}{code} -
Dynamically adding a column to a jtable - simple & urgent
I am new to using JTables.
I have read the tutorial and looked at several examples, but I am still confused as to how to add/remove columns and how to add rows to the table.
I want to have a totally dynamic table which will allow me to add/remove columns and to add rows.
The table gets the data to be displayed (and the column header values) from an outside object. I thought about writing my own table model.
Here is the code for my simple table model:
import javax.swing.table.*;
import java.util.Vector;
public class MyTableModel extends AbstractTableModel{
private Vector columnHeaders;
private Vector data;
// simple constructor
public MyTableModel() {
columnHeaders = new Vector();
data = new Vector(); // data is a vector of vectors
public int getColumnCount() {
return columnHeaders.size();
public int getRowCount() {
if (data.size() == 0) {
return 0;
Vector columnData = (Vector)data.elementAt(0);
return columnData.size();
public Object getValueAt(int row, int column) {
Vector columnData = (Vector)data.elementAt(column);
return columnData.elementAt(row);
// the method I call for dynamically adding a new empty column
public void addNewEmptyColumn(String value) {
columnHeaders.add(value);
fireTableStructureChanged();
}Here is how I use the table model with my table
import javax.swing.*;
public class Demo extends JFrame{
private JTable table;
public Demo() {
super("test");
table = new JTable(new MyTableModel());
getContentPane().add(table);
pack();
show();
public void addColumn(String value) {
MyTableModel model = (MyTableModel)table.getModel();
model.addNewEmptyColumn(value);
public static void main(String[] args) {
Demo demo = new Demo();
// here I am trying to add columns...
demo.addColumn("one");
demo.addColumn("two");
}I try to add columns, but nothing happens!!!
What am I doing wrong?
I would appreciate if someone who take himself/herslef to be a JTable expert could give me his/her e-mail and this way I won't bother the rest of the world with my stupid JTable questions...
Sincerely
NirI have another question.
What if I want to render the table headers in a certain way.
I would like to use:
TableColumn's setHeaderRenderer(TableCellRenderer headerRenderer).
But in order to do it, I need to get a TableColumn.
How do I get it from the model?
I thought about subclassing JTable and overriding:
public void tableChanged(TableModelEvent e)that function is called everytime I invoke fireTableStructureChanged().
In that function, I am assuming that a column has been added, however, when I query for JTable's getColumnCount(), I keep getting 0! -
Adding description column into wizard generated matrix report
Hi,
I currently have a matrix report that reports rows as job names and columns as media type. the intersection is the media code.
for example i have a job called abc and it has envelopes(e1,e2), base stationary (s1,s2) and inserts (i1,i2).
job envelope base stationary inserts
abc e1 s1 i1
e2 s2 i2
so far i have no problems. what i would like to do is add a description entry next to the inserts column. the description is only for the insert and only needs to be shown when an insert is present.
any ideas? i have tried adding in an additional field, however, i get some type of grouping error (my reports has just crashed so i can't get exact error)
thanks in advance for the help!Hi,
If I understood you right. Place the txt next to the insert field, then right click on the txt field and go to 'Conditional Formatting' then New. Put it in, if the value of Insert column is null, then click the 'Hide the Object' checkbox.
-Marilyn -
Adding new columns in a JTable?
How can i add a new column every time a button is pressed? I have
String columns[][] = {{"1", "2", "3"}}But i don't know how to add a new {} row...
Help?
Or can someone show me a better way to do it?Use a Collection instead of arrays.
Arrays are fixed-size. If you need a bigger array, you need to create the new one, copy the old content over and fill in the new values.
Collections hide all that complexity from you by providing simple .add() and .remove() methods.
Arrays: low-level mechanism.
Collections: more comfortable high-level mechanism -
Adding mark column into an alv
Hallo ladies and gentlemen,
how can i easily add an mark column to an alv-list?
thanks a lot,
Marcelhi,
DATA : wf_slis TYPE slis_t_fieldcat_alv.
PERFORM build_catalog USING wf_slis[].
FORM build_catalog USING wf_slis TYPE slis_t_fieldcat_alv.
.ur old fields....
*new field mark
CLEAR wf_str_slis.
wf_str_slis-fieldname = 'WF_MARK'.
wf_str_slis-checkbox = 'X'.
wf_str_slis-edit = 'X'.
APPEND wf_str_slis TO wf_slis.
endform.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
i_callback_program = sy-cprog
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME =
IS_LAYOUT =
it_fieldcat = wf_slis[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IR_SALV_LIST_ADAPTER =
IT_EXCEPT_QINFO =
I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = int_zone[]
EXCEPTIONS
program_error = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
rgds
anver
Message was edited by: Anversha s -
Adding/removing columns in jtable
Hello everyone,
i was looking for a way to add/remove columns from a jtable. The way i envision it working is... Initially have a predefined number of columns, of these only show the user say 5 of those on startup. but then provide a drop down (or list box etc) of the other column headings, so that when the user selects one... it adds it to the jtable. also to remove ..... is there a way to have a pop-up when the user right-clicks the table header and put a option to remove that column there? if not what is the best way to trigger a remove of a column? So i need a way to keep track of all the columns in case the user wants to add it again. anyone know how this can be done or any part of it?I need a intutive way for the user to remove a column from the gui (like with adding could be a dropdown box with column headers as labels).Create a custom ComboBoxModel. This model would simply contain TableColumns and display the header value in the combo box. The first combo box would display the currently showing columns. When you click on an item in the combo box:
a) remove the TableColumn from the TableColumnModel
b) remove the TableColumn from the model
c) add the TableColumn to the "hidden" combo box model
The same basic logic (but in reverse) would then apply when you click on the "hidden" combo box. -
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
}); -
Adding new column in an existing report which was build using Union
While working in OBIEE 11g I encounter an issue.
My existing report was build using UNION at Criteria Tab in Analysis. Now I have a requirement to add a new column into the same report. For each criteria I have added the new column but when I go back to the "Result Columns". I see a new field added but it is not allowing me to open or edit column properties for that new column & at the same time it is not allowing me to navigate to other tabs like Results, Promts, and Advanced.
I don’t want to build this report from scratch. Is there any workaround to get it resolved?Hi,
Just check it once the new added column data types are mismatched or not?
and the new added column should be navigated into excluded section, so u should edit the report and dragged into the table column section.
Thanks.. -
Add a new column into repository
hi
In BI11g, how to add a new column into repository?
Thanks
kaviHi kavitha,
If your adding a new column to the physical layer or BMM layer the process is same as 10g.
Steps:-
1) Right click table where you want to add the column.
2)Select new object >>physical column/BMM column
3) Enter your choice labelling and data type,if needed formula.
4) Click ok and you can see the column being added on to the table.
CHeers,
KK -
How to add one column into the t.code: cat2
Hi
I am userexits
here i want to add one column into the t.code: cat2 at particular location, and that added field have to display the data what i am selcting in that transaction.
how to do this...
thankxhi,
CATS0005
CATS0007
CATS0009
CATS0010
CATS0012.
Go through the documentations of above Enhancements to solve ur problem. I am not able to understand ur exact requirement. that is y i gave some more Enhancements.
Maybe you are looking for
-
Getting a permission error while updating a field.
hi, I want to update a field in OIM and push the same to OID. When i try to update it for like 20 times it woks for 18 times and doesnt work for couple of times. I check the log and i get the below error..... *Caused by: javax.ejb.AccessLocalExceptio
-
Charge Account is invalid in checkout and Submission of iProc 11i 11.5.10.2
Are either of you aware of any ongoing issues with iProc that would cause me the trouble detailed below.In summary, I am attempting to enter a Req against an approved project ID. I have a quote from the vendor as the materials are not in our catal
-
JSF SQL Exception missing parameter IN or OUT
Hello, I am new in JSF. I wanted to view information from table stored in Oracle database XE edition. I use jdbc driver to connect Netbeans 6.0 environment to the database. Then I set the table and SQL statement with "?". Always when I want to see th
-
How to add table Z to infoset that is using PNP or PNPCE
hello my friends... i thing that the subject explains my situation... i want to add a Z table to infoset that is using PNP or PNPCE database, then i want to use the fields of Z table to selection criteria regards and thanks in advance Mário
-
N73 - voice dialling doesn't work, portuguese name...
Hi there, 90% of the mobile phones that I had were Nokia, from the old 5110 to my latest N73. With two exceptions (a Motorola and a Siemens) I've always came back to this brand, because it had the best quality. I never, ever had a complaint, at least