HOW TO ADD COLORS TO JTABLE ROWS??
I want to change the colors of alternate rows in my JTable. I am doing so using CellRenderer, but then I am not able to view the selected rows.
tell me how can I change the row color as well as a selected row should be identifiable from others, as ordinary JTable.
thanks
Hi,
try this:
define your own DefaultTableCellRenderer like this:
class MyRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column){
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (isSelected) setBackground( Color.anyColor );
return this;
Hope it helps!
Regards, Paul
Similar Messages
-
How to add color only in header
how to add color only in header and arrange a background color selected from desktop
You can place rectangle in header section on master page which would be applied on sub pages and then fill rectangle with color.
If you are after a specific color then simply use color code and fill.
Thanks,
Sanjit -
how to add colore to the particular fields in alvs?
could u plz explain clearly with code and commentsHi,
go thr below code,
tables used -
tables: mkpf,
mseg,
lfa1,
makt.
global hashed tables used
data: begin of wa_mkpf, "header
mblnr like mkpf-mblnr,
mjahr like mkpf-mjahr,
budat like mkpf-budat,
xblnr like mkpf-xblnr,
end of wa_mkpf.
data: ht_mkpf like hashed table of wa_mkpf
with unique key mblnr mjahr
with header line.
data: st_mkpf like standard table of wa_mkpf
with header line.
data: begin of wa_mseg, " line items
mblnr like mseg-mblnr,
mjahr like mseg-mjahr,
zeile like mseg-zeile,
bwart like mseg-bwart,
charg like mseg-charg,
matnr like mseg-matnr,
lifnr like mseg-lifnr,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
end of wa_mseg.
data ht_mseg like hashed table of wa_mseg
with unique key mblnr mjahr zeile
with header line.
data st_mseg like standard table of wa_mseg
with header line.
cache structure for lfa1 records
data: begin of wa_lfa1,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
end of wa_lfa1.
data ht_lfa1 like hashed table of wa_lfa1
with unique key lifnr
with header line.
cache structure for material related data
data: begin of wa_material,
matnr like makt-matnr,
maktx like makt-maktx,
end of wa_material.
data: ht_material like hashed table of wa_material
with unique key matnr
with header line.
result table
data: begin of wa_lst, "
budat like mkpf-budat,
mblnr like mseg-mblnr,
lifnr like mseg-lifnr,
name1 like lfa1-name1,
xblnr like mkpf-xblnr,
zeile like mseg-zeile,
charg like mseg-charg,
matnr like mseg-matnr,
maktx like makt-maktx,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
mjahr like mseg-mjahr,
end of wa_lst.
data: ht_lst like hashed table of wa_lst
with unique key mblnr mjahr zeile
with header line.
data: begin of wa_lst1, " sumary by material
matnr like mseg-matnr,
maktx like makt-maktx,
erfmg like mseg-erfmg,
erfme like mseg-erfme,
color_line(4) TYPE c, " Line color
color_cell TYPE lvc_t_scol, " Cell color
celltab type LVC_T_STYL,
end of wa_lst1.
data: ht_lst1 like hashed table of wa_lst1
with unique key matnr
with header line.
structures for alv grid display.
itabs
type-pools: slis.
data: it_lst like standard table of wa_lst with header line,
it_fieldcat_lst type slis_t_fieldcat_alv with header line,
it_sort_lst type slis_t_sortinfo_alv,
it_lst1 like standard table of wa_lst1 with header line,
it_fieldcat_lst1 type slis_t_fieldcat_alv with header line,
it_sort_lst1 type slis_t_sortinfo_alv.
structures
data: wa_sort type slis_sortinfo_alv,
ls_layout type slis_layout_alv.
color management.
DATA : wa_color TYPE lvc_s_scol.
Internal table for color management.
DATA : it_color TYPE TABLE OF lvc_s_scol.
itab for input enabling.
DATA: lt_celltab TYPE lvc_t_styl. "
global varialbes
data: g_lines type i.
data: g_repid like sy-repid,
ok_code like sy-ucomm.
selection-screen
"text: Dates:
select-options: so_budat for mkpf-budat default sy-datum.
"text: Material numbers.
select-options: so_matnr for mseg-matnr.
selection-screen uline.
selection-screen skip 1.
"Text: show summary by material.
parameters: gp_bymat as checkbox default ''.
parameters: gp_hier as checkbox default 'X'.
start-of-selection.
perform get_data.
perform show_data.
end-of-selection.
FORM get_data *
form get_data.
select mblnr mjahr budat xblnr
into table ht_mkpf
from mkpf
where budat in so_budat. " make use of std index.
have we retrieved data from mkpf?
describe table ht_mkpf lines g_lines.
if g_lines > 0.
if true then retrieve all related records from mseg.
Doing this way we make sure that the access is by primary key
of mseg.
The reason is that is faster to filter them in memory
than to allow the db server to do it.
select mblnr mjahr zeile bwart charg
matnr lifnr erfmg erfme
into table ht_mseg
from mseg
for all entries in ht_mkpf
where mblnr = ht_mkpf-mblnr
and mjahr = ht_mkpf-mjahr.
endif.
fill t_lst or t_lst1 according to user's choice.
if gp_bymat = ' '.
perform fill_ht_lst.
else.
perform fill_ht_lst1.
endif.
endform.
form fill_ht_lst.
refresh ht_lst.
Example: how to discard unwanted data in an efficient way.
loop at ht_mseg.
filter unwanted data
check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
check ht_mseg-matnr in so_matnr.
read header line.
read table ht_mkpf with table key mblnr = ht_mseg-mblnr
mjahr = ht_mseg-mjahr.
clear ht_lst.
* note : this may be faster if you specify field by field.
move-corresponding ht_mkpf to ht_lst.
move-corresponding ht_mseg to ht_lst.
perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.
perform read_material using ht_mseg-matnr changing ht_lst-maktx.
insert table ht_lst.
endloop.
endform.
form fill_ht_lst1.
data: colorear.
refresh ht_lst1.
Example: how to discard unwanted data in an efficient way.
hot to simulate a collect in a faster way
loop at ht_mseg.
filter unwanted data
check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.
check ht_mseg-matnr in so_matnr.
* note : this may be faster if you specify field by field.
read table ht_lst1 with table key matnr = ht_mseg-matnr
transporting erfmg.
if sy-subrc <> 0. " if matnr doesn't exist in sumary table
" insert a new record
clear ht_lst1.
ht_lst1-matnr = ht_mseg-matnr.
perform read_material using ht_mseg-matnr changing ht_lst1-maktx.
ht_lst1-erfmg = ht_mseg-erfmg.
ht_lst1-erfme = ht_mseg-erfme.
if colorear = ''.
colorear = 'X'.
refresh it_color.
ht_lst1-color_cell[] = it_color[].
MOVE 'C410' TO ht_lst1-color_line.
else.
colorear = ' '.
refresh it_color. clear it_color.
MOVE 'MATNR' TO wa_color-fname.
MOVE '6' TO wa_color-color-col.
MOVE '1' TO wa_color-color-int.
MOVE '1' TO wa_color-color-inv.
APPEND wa_color TO it_color.
MOVE 'MAKTX' TO wa_color-fname.
MOVE '3' TO wa_color-color-col.
MOVE '1' TO wa_color-color-int.
MOVE '1' TO wa_color-color-inv.
APPEND wa_color TO it_color.
MOVE 'ERFMG' TO wa_color-fname.
MOVE '5' TO wa_color-color-col.
MOVE '1' TO wa_color-color-int.
MOVE '1' TO wa_color-color-inv.
APPEND wa_color TO it_color.
ht_lst1-color_cell[] = it_color[].
clear ht_lst1-color_line.
endif.
insert table ht_lst1.
else." a record was found.
" collect erfmg. To do so, fill in the unique key and add
" the numeric fields.
ht_lst1-matnr = ht_mseg-matnr.
add ht_mseg-erfmg to ht_lst1-erfmg.
modify table ht_lst1 transporting erfmg.
endif.
endloop.
endform.
implementation of cache for lfa1.
form read_lfa1 using p_lifnr changing p_name1.
read table ht_lfa1 with table key lifnr = p_lifnr
transporting name1.
if sy-subrc <> 0.
clear ht_lfa1.
ht_lfa1-lifnr = p_lifnr.
select single name1
into ht_lfa1-name1
from lfa1
where lifnr = p_lifnr.
if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.
insert table ht_lfa1.
endif.
p_name1 = ht_lfa1-name1.
endform.
implementation of cache for material data
form read_material using p_matnr changing p_maktx.
read table ht_material with table key matnr = p_matnr
transporting maktx.
if sy-subrc <> 0.
ht_material-matnr = p_matnr.
select single maktx into ht_material-maktx
from makt
where spras = sy-langu
and matnr = p_matnr.
if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.
insert table ht_material.
endif.
p_maktx = ht_material-maktx.
endform.
form show_data.
if gp_hier = 'X'. "no anda.
perform show_hierarchicalALV.
else.
if gp_bymat = ' '.
perform show_ht_lst.
else.
perform show_ht_lst1.
endif.
endif.
endform.
form show_hierarchicalALV.
st_mkpf[] = ht_mkpf[].
st_mseg[] = ht_mseg[].
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM =
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
IS_LAYOUT =
IT_FIELDCAT =
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
i_tabname_header =
i_tabname_item =
I_STRUCTURE_NAME_HEADER =
I_STRUCTURE_NAME_ITEM =
is_keyinfo =
IS_PRINT =
IS_REPREP_ID =
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
tables
t_outtab_header = st_mkpf
t_outtab_item = st_mseg
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.
endform.
form show_ht_lst.
"needed because the FM can't use a hashed table.
it_lst[] = ht_lst[].
perform fill_layout using 'full display'
changing ls_layout.
perform fill_columns_lst.
perform sort_lst.
g_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
is_layout = ls_layout
it_fieldcat = it_fieldcat_lst[]
it_sort = it_sort_lst
tables
t_outtab = it_lst
exceptions
program_error = 1
others = 2.
endform.
form show_ht_lst1.
"needed because the FM can't use a hashed table.
it_lst1[] = ht_lst1[].
perform fill_layout using 'Sumary by matnr'
changing ls_layout.
perform fill_columns_lst1.
perform sort_lst.
g_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
i_callback_pf_status_set = 'SET_PF_STATUS'
is_layout = ls_layout
it_fieldcat = it_fieldcat_lst1[]
it_sort = it_sort_lst
tables
t_outtab = it_lst1
exceptions
program_error = 1
others = 2.
endform.
form fill_layout using p_window_titlebar
changing cs_layo type slis_layout_alv.
clear cs_layo.
cs_layo-window_titlebar = p_window_titlebar.
cs_layo-edit = 'X'.
cs_layo-edit_mode = space.
MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.
Field that identify cell color in inetrnal table
MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.
move 'CELLTAB' TO cs_layo-stylefname.
endform. " armar_layout_stock
form set_pf_status using rt_extab type slis_t_extab.
create a new status
and then select extras -> adjust template -> listviewer
set pf-status 'VISTA'.
endform. "set_pf_status
define add_lst.
clear it_fieldcat_lst.
it_fieldcat_lst-fieldname = &1.
it_fieldcat_lst-outputlen = &2.
it_fieldcat_lst-ddictxt = 'L'.
it_fieldcat_lst-seltext_l = &1.
it_fieldcat_lst-seltext_m = &1.
it_fieldcat_lst-seltext_m = &1.
if &1 = 'MATNR'.
it_fieldcat_lst-emphasize = 'C111'.
endif.
append it_fieldcat_lst.
end-of-definition.
define add_lst1.
clear it_fieldcat_lst.
it_fieldcat_lst1-fieldname = &1.
it_fieldcat_lst1-outputlen = &2.
it_fieldcat_lst1-ddictxt = 'L'.
it_fieldcat_lst1-seltext_l = &1.
it_fieldcat_lst1-seltext_m = &1.
it_fieldcat_lst1-seltext_m = &1.
append it_fieldcat_lst1.
end-of-definition.
form fill_columns_lst.
set columns for output.
refresh it_fieldcat_lst.
add_lst 'BUDAT' 10.
add_lst 'MBLNR' 10.
add_lst 'LIFNR' 10.
add_lst 'NAME1' 35.
add_lst 'XBLNR' 15.
add_lst 'ZEILE' 5.
add_lst 'CHARG' 10.
add_lst 'MATNR' 18.
add_lst 'MAKTX' 30.
add_lst 'ERFMG' 17.
add_lst 'ERFME' 5.
add_lst 'MJAHR' 4.
endform.
form fill_columns_lst1.
set columns for output.
refresh it_fieldcat_lst1.
add_lst1 'MATNR' 18.
add_lst1 'MAKTX' 30.
add_lst1 'ERFMG' 17.
add_lst1 'ERFME' 5..
endform.
Horacio Zapettini
Program to Calculate FI Opening Balance
How to find the Opening balance for a given period in FI Module for a Particular GL A/c.
I was calculated opening balance, code is below maybe it will be helpful.
*find period.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = s_budat-low
i_periv = i_tab-periv "'K4'
IMPORTING
e_buper = v_donem
e_gjahr = v_gjahr
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
*calc opening balance hesabý
SELECT * FROM knc1 WHERE kunnr = i_tab-kunnr
AND bukrs = i_tab-bukrs " s_bukrs
AND gjahr EQ v_gjahr.
v_dnm = v_donem.
opening balance first calc > old year ,
WHILE v_dnm > 1.
v_dnm = v_dnm - 1.
CONCATENATE 'knc1-um' v_dnm 's' INTO v_field_name_borc.
CONCATENATE 'knc1-um' v_dnm 'h' INTO v_field_name_alacak.
ASSIGN (v_field_name_borc) TO old
add days which is from selected date-low month
IF v_donem > 1.
v_dnm = v_donem - 1.
ELSE.
v_dnm = v_donem.
ENDIF.
SELECT SINGLE * FROM t009b WHERE periv = i_tab-periv "'K4'
AND bdatj = s_budat-low+0(4)
AND poper = v_dnm.
t009b-butag = t009b-butag + 1.
IF s_budat-low+6(2) NE t009b-butag.
v_date_high = s_budat-low - 1.
IF v_donem = 1.
v_date_low = s_budat-low.
v_date_low+4(4) = '0101'.
ELSE.
CONCATENATE t009b-bdatj t009b-bumon t009b-butag INTO
v_date_low.
ENDIF.
SELECT * FROM bsad WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
AND kunnr = i_tab-kunnr
AND budat BETWEEN v_date_low AND
v_date_high
AND umskz = space
AND blart IN s_blart.
IF bsad-shkzg = 'S'.
i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsad-dmbtr ).
ELSEIF bsad-shkzg = 'H'.
i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsad-dmbtr ).
ENDIF.
ENDSELECT.
SELECT * FROM bsid WHERE bukrs EQ i_tab-bukrs "IN s_bukrs
AND kunnr = i_tab-kunnr
AND budat BETWEEN v_date_low AND
v_date_high
AND umskz = space
AND blart IN s_blart.
AND gsber IN gsber.
IF bsid-shkzg = 'S'.
i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsid-dmbtr ).
ELSEIF bsid-shkzg = 'H'.
i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsid-dmbtr ).
ENDIF.
ENDSELECT.
ENDIF.
"opening balance ( þirket bazlý )z1 degeri
i_tab-z1 = i_tab-z1 + ( knc1-umsav + i_tab-dmbtr_s - i_tab-dmbtr_h ).
for israel
i_tab-dmbtril_s = i_tab-dmbtr_s .
i_tab-dmbtril_h = i_tab-dmbtr_h .
ENDSELECT.
reward if useful. -
How to set color of a row depending on the value of column in JTable?
Hi All,
I have a JTable that add rows when the user clicks on the button. In this way there can be any no. of rows in my table. My table contains five columns. When a new row is added , it is added with new data each time. Also the data of the rows keep on changing time to time.
My problem is that when the data value for the third column comes out to be -ve then color of the row should be red and if its value is +ve then the color of the row should be green.
I have tried for this in the way but it is not working properly.
public Component prepareRenderer(TableCellRenderer renderer,int rowIndex, int vColIndex)
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if(rowIndex<table.getRowCount() && change<0 )
c.setForeground(Color.red);
c.setFont(new Font("TimesRoman",Font.PLAIN,11));
else if(rowIndex<table.getRowCount() && change>0)
c.setForeground(new Color(20,220,20));
c.setFont(new Font("TimesRoman",Font.PLAIN,11));
return c;
where change is the value of the third column.
Any help is highly appreciated.
Thanx in advance.
Regards,
Har KrishanPerhaps you'll find this link useful. It gives a general idea of how you can create and adjust your custom renderer:
http://www.senun.com/Left/Programming/Java_old/Examples_swing/JTableExamples4.html
Hope it helps.
Eugene -
How can I color just one row in a table?
Hello,
I'm implementing cut/copy/paste and I want that when I perform cut the row color will be pale/ghost than the regular selectionRow background. And I want this pale color to stay for this row regardless if I select now other rows. I need it for JTable, JTree & JList. So my question is how can I color a row in those components (permanently - till I release it)
Thanks
Bnaya.Hi,
for a JTable I would suggest the following:
1.in the body of the class
int ghostrow = -1;
Color ghostColor = Color.lightGray; // for example2. overwrite the prepareRenderer-method this way
public Component prepareRenderer(TableCellRenderer render,int row, int column) {
Component c = super.prepareRenderer(renderer,row,column);
if (row==ghostrow) c.setBackground(ghostColor);
return c;
}3. add a method in your JTable subclass for setting of the ghostrow like this, in order to force the JTable to update its display after setting ghostrow
public void setGhostRow(int row) {
TableModel tm = getModel();
int currow = tm.getRowCount();
int oldrow = ghostrow;
ghostrow = -1;
if (row<currow) ghostrow = row;
// next 2 rows in normal mode displayed, because it will not print the greater than symbol correctif ((oldrow>-1) && (oldrow<currow)) tableChanged(new TableModelEvent(tm,oldrow));
if ((ghostrow>-1) && (ghostrow<currow)) tableChanged(new TableModelEvent(tm,ghostrow));
For the other classes, you want this effect to happen in, try to find a similar method, that is central and do it in a similar way there.
greetings Marsian -
How can I add data into JTable, for instance ("Mike", "Gooler", 21).
How can I add data into JTable, for instance ("Mike",
"Gooler", 21).You will have very good results if you segregate out the table model as a seperate user class and provide a method to add a row there. In fact, if you use the table to reflect a database table you can add the row inplace using the existing cursor. I believe it's TableExample2 in the jdk\demo\jfc\TableExamples that has a very good example of this.
Walt -
How to setForeground for individual JTable rows???
How do you set the foreground and background colors for individual rows in a JTable? I don't want every row to change, just the rows I select programmatically (not via the GUI). The JTable.setForeground() from the JComponent base class changes all the rows. Any ideas?
Hi!
Write your own renderer and set it as defaultRenderer on your table. Something like this:
// Using Object.class makes sure the renderer will be used regardless of column class type
myTable.setDefaultRenderer(Object.class, new MyRenderer(Color.red));And the renderer:
class MyRenderer extends javax.swing.table.DefaultTableCellRenderer
private Color m_mySelectedColor;
public MyRenderer(Color par_mySelectedColor)
m_mySelectedColor = par_mySelectedColor;
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
Component returnComponent = super.getTableCellRendererComponent(
table,value,isSelected,hasFocus,row,column);
if (isSelected)
returnComponent.setBackground(m_mySelectedColor);
else
returnComponent.setBackground(table.getBackground());
return returnComponent;
}smedman -
How to add actionlistener to JTable?
I have created a JTable. and I would like to while I double-click any row of JTable, I go to next frame. How can I add actionlistener to each row?
Here's an example:
TableF modeltable = new TableF();
JTable FuncsTable = new JTable(modeltable);
FuncsTable.addMouseListener(mlTable);
MouseListener mlTable = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if ( e.getClickCount() == 2 ) {
System.out.println( FuncsTable.getSelectedRow());
your code -
How to add colors to a CSV file?
Hi there,
I'm exporting data to a CSV file using printWriter.
Question: is it possible to add colors, bold text or stretch the length of a column in the produced CSV file?
This, of course, should be the end result of the file (not do it when the file is open)
Thank you!xianwinwin wrote:
Question: is it possible to add colors, bold text or stretch the length of a column in the produced CSV file?Of course if you assumed that you'd be looking at the file with a fixed-width font, you could insert a bunch of tabs or spaces to get columns to match up, but I strongly advise you not do that. I think of CSV as a poor-man's excel data file or perhaps a flat database file, but most importantly it holds data in a standard format that can be read and manipulated by many different programs, including ones you write yourself. It is not meant to be for pretty visualization. Try to pretty it up and you possibly ruin it's main reason for existing. For nice visualization I'd create a small app that read the CSV, formatted it nicely and either displayed the data or stored it in some pretty format as a non-CSV file. -
How to add events in JTable fields
Hello friends i m working with file transfer client server project in my college.In my client part i have used JTable with AbstractTableModel.
In my JTable it list the current directory files and directories under current directory .
now how can i add events to the the directories that it shows on JTable so that when i click on directory it displays files under that selected directory.
can anyone help me in that.
I will send you my code for that project if anyone can help me.
please help me to do thatYou can handle row selections with selection listener but if you want to handle double clicks you can use something similar to this:
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e)
int column = table.columnAtPoint(e.getPoint());
int row = table.rowAtPoint(e.getPoint());
Object cellValue = table.getValueAt(row, column);
// Insert files below clicked row
});Please, be more patient in the future -you would probably get an answer if you just posted to any of these two forums. -
How to add more than one rows to form, without submitting to database
Hi!
I have an updatable report similar to this http://htmldb.oracle.com/pls/otn/f?p=31517:163:3149788972931514::NO
Now, as much as I'm aware the standard thing is that when I add a row, put in data and then add a nother row, previous data is commited and another row is added.
I, on the other hand, would like to add as much rows as I need and populate them with data and then submitt all the changes in the end. So the user nows, that when he SAVES data it's submited to db, not in between.
My form is not standard, it uses SQL, and APEX_ITEM, I even have more updatable reports on one page etc, so I presume, processes like AddRowToTabularForm don't come handy.
Thanx for any suggestions,
N.user10824271 wrote:
I, on the other hand, would like to add as much rows as I need and populate them with data and then submitt all the changes in the end. So the user nows, that when he SAVES data it's submited to db, not in between.So you would have a select list for the number of rows?
Add that X(select list) number of rows, populate rows, then insert?
Is that how you vision it?
Did you try this? [Tabular Form Add Rows Using Item | http://htmldb.oracle.com/pls/otn/f?p=31517:209:3291656615866862:ADD:NO:::]
Edited by: MHolley on Mar 11, 2009 8:53 AM -
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.
-
How to Add and delete a row while using Abstract Table Model
Hi,
I need to do the following functionalities in JTable.I've done tht but a small problem.
1. Adding a row (Using addRow() method from DefaultTableModel).
2. Deleting a row(Using setRowCount() method from Default Table Model).
3. Sorting the table based on the selection of column(Using TableSorter which is using AbstracTableModel).
As the sorting is mandatory i've to change my model to Abtract Table Model
The problem is this Abstract Table Model doesn't have any methods to Add a row or deleting a row (setRowCount()).If anybody has written any utility method for this using Abstract Table Model help me.Using TableSorter which is using AbstracTableModel).If your talking about the TableSorter class from the Swing tutorial, then you create the TableSorter class by passing it a TableModel. There is no reason you can't use the DefaltTableModel.
I changed the code in TableSorterDemo as follows:
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new BigDecimal(1), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new BigDecimal(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new BigDecimal(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new BigDecimal(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new BigDecimal(10), new Boolean(false)}
DefaultTableModel model = new DefaultTableModel(data, columnNames)
public Class getColumnClass(int c)
return getValueAt(0, c).getClass();
TableSorter sorter = new TableSorter(model);
// TableSorter sorter = new TableSorter(new MyTableModel()); //ADDED THIS -
How to add Chekbox in Jtable?
I am working on Swing application and my requirement is add new column that dispay the checkboxes, so user have the access to check/uncheck row for further process.
In application 3 tabbedpanes are there & in the 3rd tabbedpane table data is displaying.
//Code snippet
public class AIProductPropertiesUI
private productsTablemodel productmodel = null;
private String [] pNames = {"select","type","name","revision","marketing","relationship"};
public JPanel getMiscPanel()
productmodel= new productsTablemodel();
table = new JTable(productmodel);
protected class productsTablemodel extends AbstractTableModel
Vector productDetails ;
productsTablemodel()
productDetails = model.getProductDetails();
headerNames = model.getLabelNameMapping();
public Object getValueAt(int rowIndex, int columnIndex)
if (productDetails.size()>0)
Hashtable ht = (Hashtable) productDetails.get(rowIndex);
//ht contains the list of values for all the column as in pNames[].
// dynamic value for Select column is ""(blank string)
String str = "" ;
if(ht.containsKey(pNames[columnIndex]))
str = (String) ht.get(pNames[columnIndex]);
return str;
}else{
return null;
I tried following ways-
1)if(column==0)
return new JCheckBox("str",true);
here output is dispaying complete details of Checkbox
/* output for checkbox cell is --- javax.swing.JCheckBox[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,
border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@b1b4c3,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,
disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=false,paintFocus=true,
pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=str]*/
2)overiding public Class getColumnClass(int column)
if(column==0)
return Class.forName("java.lang.Boolean");
till this point its working fine... but in above code method public Object getValueAt(int rowIndex, int columnIndex)
I am checking if(Column==0)
return Class.forName("java.lang.Boolean");
here it is throwing ClassCastException.. java.lang.Class cannot be cast to java.lang.Boolean
Please provide me solution aas soon as possible...coz from past 2 days i m stucking on this and due to this not able to move ahead on my application development.
Thanks in Advance
Sharadmore time researching instead of cross-posting would be better for you
[http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=018027] -
How to add JTextArea in JTable
Hi..
I want to add JTextArea in my table in one of the column of JTable. I have already written a code which implements TablecellEditor and TableCellRenderer. I have already succeeded to set textarea in one cell for multiple line but when i go to another cell my previous value disappears. Can anybody tell me the solution.I think the reason that this is happening, is that you have to override the setValue method in TableModel, inorder for the value to be displayed correctly.
Another thing.
I too am trying to implement a textarea as one of the cells in a col.
But the problem is that when I create my celleditor extends TextArea and implements TableCellEditor, and compile it says that all eventLsiteners are already implemented .
And if I just extend the AbstractCellEditor, and return it in the method getCellEditor, it says incompatible types.
Can you tell me how to implement a CustomCellEditor
Thanks,
Maybe you are looking for
-
How to use IWEB for multiple websites?
Okay. I have two websites. One on a 3rd party, one on .MAC. Computer 1 = .MAC website Computer 2= 3rd party website I want to use computer 2 to edit my .MAC website and moved the DOMAIN file but haven't open it in iWEB on the second computer as I nee
-
Is there a way to integrate paypal with Dreamweaver Spry Tab Panels? I have a site and have used the add to cart code outside of the spry tabs and it works fine as in adds my product to the paypal shopping cart. When I put the same code into the sp
-
Crystal XI Runtime with Windows 2008 Server
Hi all We have been using Crystal for many years with our application, distributing Crystal Runtime with it. We have our own DLL which interacts with Crystal to display a setup screen to get the user to enter values for the parameters within the repo
-
Repeating sound effect problem
I am looking to get a record scratch sound to play throughout my entire song. I have a MIDI ambient record scratch. What is the easiest way to get it to play in the whole song.
-
How find out error in Preparestatement?
i am using jdbc,servlet,html client msaccess database have 155 fields in database.there is no errors in compile. i am inserting data from html to database thro servlet i am inserting data thro preparedstatement using( ?) marks. but executeUpdate is n