JTable user resize columns with grid?
Is it possible to allow a user to resize columns not just through the table header, but with the vertical grid lines?
There is no method that allows you to toggle this
feature on/off if thats what you are asking.Yes, thats what I was asking.
If you want to implement this type of functionality
yourself then take a look at the source code for
JTableHeader to see how its done.Thanks, I'll look into that - though it would be cool if that was already a feature of JTable.
Similar Messages
-
How to Insert a User Defined Column with CheckBox In ADF Swings
I have create JTable by dragging a view object from Data Control Palette .But apart from columns listed in JTable i need to insert a User Defined column with Check Box selection option in each row .
Can any one help me out to sort the problem.
Regards
Bhanu Prakash
Message was edited by:
user579125I retrieve 10 column from Database and build JTable. But apart from 10 column displayed i need to display one more column( User Defined) at run time with the check box option for each row . Because on select of corresponding check box i need to do some mathematical calculation. add also How do i know whether check box is selected or not.
Regards
Bhanu Prakash -
JTable - Setting multiple columns with different color
Building excel type functionality in Java.
I have a database table like this
id PK
min_x
max_x
min_y
max_y
color
1. I need to create a JTable having 50 colums and 50 rows.
2. I need to select mouse selection color.
3. On mouse selection I have to change the Background-color or foreground-color of JTable cells and on click of save button I need to get the data in following manner column start of particular color as min_x, column end of particular color as max_x, row start of particular color as min_y, row end of particular color as max_y, and bg or foreground color.
can some one tell me is there a way to do this. Or any other way to implement this functionality.Crossposted:
http://forum.java.sun.com/thread.jsp?thread=541598&forum=422&message=2625937
http://forum.java.sun.com/thread.jsp?thread=541597&forum=57&message=2625933
http://forum.java.sun.com/thread.jsp?thread=541595&forum=31&message=2625929
http://forum.java.sun.com/thread.jsp?thread=541594&forum=54&message=2625922 -
JTable: Easy groupable column headers with hideable columns
Hi All,
I have a requirement to make a JTable which displays
columns with 2 values - a current value and an old one.
The old value can be hidden or shown by user preference.
The values are not editable. The 2 values have a single
heading.
I've been mucking about with GroupableTableHeader and
HideableTableColumnModel and all that. This way of
solving the problem requires siginificant coding.
Then I had an idea - just use the TableCellRenderer to
make it look like 2 columns ! This fits my requirements
and is much simpler.
So for anyone who has the same requirement, here is
some sample code. I think you'll all agree that in my
specific case it is a very good way of providing the needed
functionality.
Here is the sample code:
import javax.swing.*;
import javax.swing.border.AbstractBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
public class DoubleColumnTable extends JTable {
private boolean secondValueVisible = true;
public DoubleColumnTable() {
super();
setModel(new AbstractTableModel() {
public String getColumnName(int column) {
return column + "";
public int getColumnCount() {
return 5;
public int getRowCount() {
return 5;
public Object getValueAt(int rowIndex, int columnIndex) {
return new Integer[]{new Integer(rowIndex), new Integer(columnIndex + 10)};
setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Integer[] twoValues = (Integer[])value;
JPanel panel = new JPanel();
if (secondValueVisible) {
panel.setLayout(new GridLayout(0, 2));
JLabel firstLabel = new JLabel(twoValues[0].toString(), JLabel.CENTER);
JLabel secondLabel = new JLabel(twoValues[1].toString(), JLabel.CENTER);
secondLabel.setBackground(Color.lightGray);
secondLabel.setOpaque(true);
secondLabel.setBorder(new LeftBorder());
panel.add(firstLabel);
panel.add(secondLabel);
} else {
panel.setLayout(new GridLayout(0, 1));
JLabel firstLabel = new JLabel(twoValues[0].toString(), JLabel.CENTER);
panel.add(firstLabel);
return panel;
private void toggle() {
secondValueVisible = !secondValueVisible;
repaint();
class LeftBorder extends AbstractBorder {
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.setColor(Color.gray);
g.drawLine(x, y, x, height);
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300, 300);
frame.setLocation(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = frame.getContentPane();
final DoubleColumnTable table = new DoubleColumnTable();
contentPane.add("North", new JButton(new AbstractAction("Toggle") {
public void actionPerformed(ActionEvent e) {
table.toggle();
contentPane.add("Center", new JScrollPane(table));
frame.setVisible(true);
}Message was edited by:
NY_Consultant
Message was edited by:
NY_Consultant
Message was edited by:
NY_ConsultantThis should read
"I have a table with column headers and a row headers using a single column from a second table." -
Can i set only 1 column in a jtable to resize?
Hi,
I want to set only the columns with "Strings" as content to be resizable inside my jtable. and leave those which are ints, as a fixed size, but I haven't been able to find a way of setting the resizing options for a specific column...
any ideas?You would need to check the column number and the data type in the column being resized and force it back to a set value if it was not a column with a string in it. Remember the user can swap the columns.
rykk -
For all users having probs with OO ALV Grid
I wanted to put this in the WIKI but it keeps bombing out when I try and save so I've put this here -- Maybe a MOD can move it for me.
This generic class should give you far more insite into using an EDITABLE ALV table than the standard documentation.
If you follow the steps you should be able to code very quickly a decent useable ALV OO program which can retrieve and manipulate data very easily. The events are (hopefully) well documented as are all the steps.
Once you understand the basics you can add more functionality like colouring Cells, adding hyperlinks etc etc.
I've always found that stupid SEAT / AIRLINE application SAP uses for its examples far too overblown and in reality who would ever use a SAP system for Airline reservations anyway.
The class here describes a much simpler application which CLEARLY (I hope) explains how the whole thing works.
Jimbo's generic class for using the OO ALV GRID Class CL_GUI_ALV_GRID
from an application program to display and manipulate ANY table
with minimal coding needed in the Calling application program.
Handles the following EVENTS
1) TOOLBAR BUTTONS
(you can add more to the toolbar method
if you need even more functionality).
2) DOUBLE CLICK
3) ENTER KEY PRESSED
4) DATA CHANGED
5) DATA CHANGED FINISHED
Methods available
PUBLIC METHODS ( Can be called directly from the application program).
1) display_grid displays grid with toolbar
Table and FCAT are built dynamically - user only needs to
define the table structure (can be DDIC or User fields)
2) change_title - changes title at the top of the Grid
3) refresh_grid - refreshes grid after table updated etc.
4) build_dynamic_structures - this method creates a dynamic table and a dynamic FCAT
using the structure defined in the calling application program
PRIVATE METHODS (Internal Methods used within the class)
1) verwerk - returns to FORM VERWERK in calling application program
(Via Toolbar). The application program can then do any special processing
at this point e.g update SAP tables etc.
2) download_to_excel (via Toolbar). This creates an EXCEL spreadsheet
directly which can be downloaded / saved to a file if required,
3) return_structure - internal method returns the structure
of the table defined in the calling application program. This is needed in order
to build the dynamic table and Field Catalog.
4) create_dynamic_table - creates a dynamic table from the structure defined in
the calling application program
5) create_dynamic_fcat - creates the dynamic field catalog from the structure
defined in the application program.
6) dubbleklik entered when user double clicks a cell
activated by EVENT DOUBLE_CLICK.
returns to FORM DUBBELKLIK in the
calling application program
COOKBOOK STEP BY STEP instructions on how to use this class
in your application program.
In the application program :
1) define a blank screen 100 - SE51 with a custom container
on it called CCONTAINER1.
you need the following logic in the screen
The PAI is only used if you have defined a STATUS with SE41 and you exit the
application program via the standard SAP buttons on the
top of the Screen (NOT the GRID toolbar).
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
2) (optional) define a STATUS with a titlebar - SE41
you only need this if you want the standard EXIT and menu buttons on the
top line of the screen
3) If you want to have your OWN colum names on the grid
add the following macro to the start of your program
DEFINE col_name.
read table it_fldcat into wa_it_fldcat index &1.
wa_it_fldcat-coltext = &2.
modify it_fldcat from wa_it_fldcat index &1.
END-OF-DEFINITION.
4) Define the following Field symbols
<fs1> TYPE ANY,
<fs2> TYPE STANDARD TABLE,
<fs3> TYPE ANY,
<field_catalog> TYPE STANDARD TABLE,
<dyn_table> TYPE STANDARD TABLE,
<orig_table> TYPE STANDARD TABLE,
<dyn_field>,
<dyn_wa>.
5) After the field-symbols add the code in this class
as an INCLUDE
e.g INCLUDE ZZJIMBOXX_INCL.
6) define your Internal table as follows
TYPES: BEGIN OF s_elements,
Your structure
your structure etc.
END OF s_elements.
For example
INCLUDE <icon>.
TABLES: VAPMA.
*TYPES: BEGIN OF s_elements,
vbeln TYPE vapma-vbeln,
posnr TYPE vapma-posnr,
matnr TYPE vapma-matnr,
kunnr TYPE vapma-kunnr,
werks TYPE vapma-werks,
vkorg TYPE vapma-vkorg,
vkbur TYPE vapma-vkbur,
status TYPE c,
*END OF s_elements.
7) Define the following data IN YOUR APPLICATION PROGRAM
(note here only data is described
that relates to using THIS CLASS. Data purely used internally
in the application program is NOT shown here).
DATA: z_object TYPE REF TO zcl_dog, "Instantiate our class
grid_container1 TYPE REF TO cl_gui_custom_container,
t_elements TYPE TABLE OF s_elements, "refers to our ITAB
wa_elements TYPE s_elements,
wa_dyn_table_line TYPE REF TO DATA,
it_fldcat TYPE lvc_t_fcat,
i_gridtitle TYPE lvc_title,
wa_it_fldcat TYPE lvc_s_fcat,
new_table TYPE REF TO DATA,
dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
row_id TYPE sy-index.
8) insert the following code at the start of the application program.
*START-OF-SELECTION.
*CALL SCREEN 100.
*END-OF-SELECTION.
*MODULE status_0100 OUTPUT.
*ASSIGN wa_elements TO <fs1>.
*CREATE OBJECT z_object EXPORTING z_object = z_object. "Instantiate the class
*CALL METHOD z_object->build_dynamic_structures
CHANGING it_fldcat = it_fldcat.
9) if you inserted the macro in step 3) then
define your own column names as follws
col_name 1 'Name1'.
col_name 2 'Name2'.
etc. The number is the colum number you want and the name is
the name you want to assign to the column.
for example using the table shown above
col_name 1 'Order Nr'.
col_name 2 'Item'.
col_name 3 'Material'.
col_name 4 'Customer'.
col_name 5 'Plant'.
col_name 6 'Sales Org'.
col_name 7 'Sales Office'.
col_name 8 'Status'.
10) perform a routine that fills your dynamic table and
display the GRID. If you created a status with SE41 you can set
a title etc. Further processing is dependent on the users action
after the GRID is displayed for example if a Cell is double clicked,
dat is entered, a toolbar button is pressed or a SAP ICON on top of the screen is pressed.
PERFORM populate_dynamic_itab.
CALL METHOD z_object->display_grid
CHANGING it_fldcat = it_fldcat.
SET PF-STATUS '0001'.
SET TITLEBAR '000'.
ENDMODULE.
11) If you added a STATUS via SE41 you can exit the program via the
standard SAP buttons at the top of the screen
otherwise exit via the exit button on the toolbar.
You only need this piece of code if you defined a STATUS in the application program
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'RETURN'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
12) to populate the dynamic table you only need to code something like this
remember the class has already created and structured the field-symbol <dyn_table>
so you don't have to do anything other than just select the fields you want
filled and from what data source(es).
*FORM populate_dynamic_itab.
*SELECT vbeln posnr matnr kunnr werks vkorg vkbur
UP TO 200 rows
FROM vapma
INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.
if you want to keep the original table before making any changes etc code
the following
create 2nd Dyn table to hold original data. We can use
the same field catalog as for the original table
as we are just creating an identical copy here.
*CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <orig_table>.
CREATE DATA dy_line LIKE LINE OF <orig_table>.
ASSIGN dy_line->* TO <dyn_wa>.
<orig_table> = <dyn_table>.
ENDFORM.
13) you need these 2 processing routines in your application program.
FORM VERWERK. "Entered from VERW on toolbar
*break-point 1.
Orig table is in dynamic table <orig_table>
ALV GRID changed table is in <dyn_table>.
*Loop at <orig_table> into <dyn_wa>.
Do what you want here
end
endloop.
ENDFORM.
*form dubbleklik using "Entered when a cell is double clicked
e_row type LVC_S_ROW
e_column type LVC_S_col
es_row_no type lvc_s_roid.
break-point 1.
Get Row id into a variable for this program.
row_id = e_row.
SET TITLEBAR '001'. "If you defined a status in SE41
i_gridtitle = 'Grid Title Changed'.
CALL METHOD z_object->change_title
EXPORTING i_gridtitle = i_gridtitle.
PERFORM refresh.
endform.
The REFRESH routine is optional but after a double click I assume
you want to do some processing
and re-display the data
so as a sample code something like
*FORM refresh.
data: ord_nr TYPE vapma-vbeln. "Your data
*READ TABLE <dyn_table> index row_id into wa_elements.
ord_nr = wa_elements-vbeln.
You've now got the Row double clicked so pick out the data element(s)
you wnat to process and do your processing
*set parameter id 'AUN' field ord_nr.
*CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.
You can update the dynamic table for example
*wa_elements-status = 'C'.
*modify <dyn_table> from wa_elements index row_id.
now redisplay the updated grid.
*CALL METHOD z_object->refresh_grid.
*ENDFORM.
*************Class ZCL_DOG*************
CLASS zcl_dog DEFINITION.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING
z_object TYPE REF TO zcl_dog,
display_grid
CHANGING
it_fldcat TYPE lvc_t_fcat,
build_dynamic_structures
CHANGING it_fldcat TYPE lvc_t_fcat,
change_title
IMPORTING
i_gridtitle TYPE lvc_title,
refresh_grid.
PRIVATE SECTION.
METHODS:
on_user_command FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm
sender,
on_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
on_dubbelklik FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row
e_column
es_row_no,
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed,
handle_data_changed_finished
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified
et_good_cells,
verwerk
IMPORTING program TYPE sy-repid,
download_to_excel,
dubbleklik
IMPORTING
e_row type LVC_S_ROW
e_column TYPE LVC_S_COL
es_row_no type lvc_s_ROID
program type sy-repid,
return_structure,
create_dynamic_fcat
EXPORTING it_fldcat TYPE lvc_t_fcat,
create_dynamic_table
IMPORTING it_fldcat TYPE lvc_t_fcat
EXPORTING dy_table TYPE REF TO DATA.
DATA:
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
zog LIKE LINE OF lr_rtti_struc->components, "RTTI
wa_it_fldcat TYPE lvc_s_fcat,
it_fldcat TYPE lvc_t_fcat,
dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
struct_grid_lset TYPE lvc_s_layo,
e_row TYPE LVC_S_ROW,
e_column TYPE lvc_s_col,
es_rowid TYPE lvc_s_roid,
grid_container1 TYPE REF TO cl_gui_custom_container,
grid1 TYPE REF TO cl_gui_alv_grid,
ls_layout TYPE kkblo_layout,
lt_fieldcat_wa TYPE kkblo_fieldcat,
l_mode TYPE raw4,
celltab TYPE LVC_T_STYL,
wa_celltab TYPE lvc_s_styl,
lt_fieldcat TYPE kkblo_t_fieldcat,
l_tabname TYPE slis_tabname.
TYPES:
struc LIKE zog.
DATA:
zogt TYPE TABLE OF struc.
ENDCLASS.
CLASS zcl_dog IMPLEMENTATION.
METHOD constructor.
CREATE OBJECT grid_container1
EXPORTING
container_name = 'CCONTAINER1'.
CREATE OBJECT grid1
EXPORTING
i_parent = grid_container1.
SET HANDLER z_object->on_user_command for grid1.
SET HANDLER z_object->on_toolbar for grid1.
SET HANDLER Z_OBJECT->handle_data_changed_finished FOR grid1.
SET HANDLER Z_OBJECT->on_dubbelklik FOR grid1.
CALL METHOD grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
ENDMETHOD.
METHOD refresh_grid.
CALL METHOD cl_gui_cfw=>flush.
CALL METHOD grid1->refresh_table_display.
ENDMETHOD.
METHOD on_dubbelklik.
CALL METHOD me->dubbleklik
EXPORTING
e_row = e_row
e_column = e_column
es_row_no = es_row_no
program = sy-repid.
break-point 1.
ENDMETHOD.
METHOD handle_data_changed.
Insert user code here if required
this method is entered if user ENTERS DATA.
ENDMETHOD.
METHOD handle_data_changed_finished.
Insert user code here if required
Method entered here after data entry has finished.
ENDMETHOD.
METHOD return_structure.
lr_rtti_struc ?= cl_abap_structdescr=>DESCRIBE_BY_DATA( <fs1> ).
zogt[] = lr_rtti_struc->components.
ASSIGN zogt[] TO <fs2>.
ENDMETHOD.
METHOD create_dynamic_fcat.
LOOP AT <fs2> INTO zog.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
APPEND wa_it_fldcat TO it_fldcat .
ASSIGN it_fldcat[] TO <field_catalog>.
ENDLOOP.
ASSIGN it_fldcat[] TO <field_catalog>.
ENDMETHOD.
METHOD download_to_excel.
break-point 5.
CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'
EXPORTING
it_fieldcat_lvc = <field_catalog>
is_layout_lvc = m_cl_variant->ms_layout
is_tech_complete = ' '
IMPORTING
es_layout_kkblo = ls_layout
et_fieldcat_kkblo = lt_fieldcat.
LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
CLEAR lt_fieldcat_wa-tech_complete.
IF lt_fieldcat_wa-tabname IS initial.
lt_fieldcat_wa-tabname = '1'.
MODIFY lt_fieldcat FROM lt_fieldcat_wa.
ENDIF.
l_tabname = lt_fieldcat_wa-tabname.
ENDLOOP.
CALL FUNCTION 'ALV_XXL_CALL'
EXPORTING
i_tabname = l_tabname
is_layout = ls_layout
it_fieldcat = lt_fieldcat
i_title = sy-title
TABLES
it_outtab = <dyn_table>
EXCEPTIONS
fatal_error = 1
no_display_possible = 2
others = 3.
IF sy-subrc <> 0.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMETHOD.
METHOD create_dynamic_table.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = dy_table.
ENDMETHOD.
METHOD build_dynamic_structures.
CALL METHOD me->return_structure.
CALL METHOD me->create_dynamic_fcat
IMPORTING
it_fldcat = it_fldcat.
CALL METHOD me->create_dynamic_table
EXPORTING
it_fldcat = it_fldcat
IMPORTING
dy_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDMETHOD.
METHOD display_grid.
struct_grid_lset-edit = 'X'. "To enable editing in ALV
struct_grid_lset-grid_title = 'Bulkwijzigingen inkoopprijzen'.
struct_grid_lset-ctab_fname = 'T_CELLCOLORS'.
struct_grid_lset-stylefname = 'CELLTAB'.
CALL METHOD grid1->set_ready_for_input
EXPORTING
i_ready_for_input = '1'.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
ENDMETHOD.
METHOD change_title.
CALL METHOD grid1->set_gridtitle
EXPORTING
i_gridtitle = i_gridtitle.
ENDMETHOD.
METHOD on_user_command.
CASE e_ucomm.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'EXCEL'.
CALL METHOD me->download_to_excel.
WHEN 'SAVE'.
WHEN 'VERW'.
CALL METHOD me->verwerk
EXPORTING
PROGRAM = SY-REPID.
ENDCASE.
ENDMETHOD. "on_user_command
METHOD on_toolbar.
User can add extra functionality by adding extra
buttons if required. Functionality can also be simplified by removing buttons.
DATA: ls_toolbar TYPE stb_button.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'EXIT' TO ls_toolbar-function.
MOVE SPACE TO ls_toolbar-disabled.
MOVE icon_system_end TO ls_toolbar-icon.
MOVE 'Click2Exit' TO ls_toolbar-quickinfo.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'SAVE' TO ls_toolbar-function.
MOVE SPACE TO ls_toolbar-disabled.
MOVE icon_system_save TO ls_toolbar-icon.
MOVE 'Save data' TO ls_toolbar-quickinfo.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'EDIT' TO ls_toolbar-function.
MOVE SPACE TO ls_toolbar-disabled.
MOVE icon_toggle_display_change TO ls_toolbar-icon.
MOVE 'Edit data' TO ls_toolbar-quickinfo.
MOVE 'EDIT' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'VERW' TO ls_toolbar-function.
MOVE SPACE TO ls_toolbar-disabled.
MOVE icon_businav_process to ls_toolbar-icon.
MOVE 'Verw.' TO ls_toolbar-quickinfo.
MOVE 'VERW' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'EXCEL' TO ls_toolbar-function.
MOVE SPACE TO ls_toolbar-disabled.
MOVE icon_xxl TO ls_toolbar-icon.
MOVE 'Excel' TO ls_toolbar-quickinfo.
MOVE 'EXCEL' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD verwerk.
PERFORM verwerk IN PROGRAM (program).
LEAVE PROGRAM.
ENDMETHOD.
METHOD dubbleklik.
PERFORM dubbleklik IN PROGRAM (program)
USING
e_row
e_column
es_row_no.
ENDMETHOD.
ENDCLASS.
Cheers
JimboHi Dinu,
Before analysing ALV, please cross check the behaviour of the calling program.
Is the control really going to the application server when you do all the above process?
If so, when user makes some changes are they saved in the data base / affected the internal table which you are using for ALV?
Regards
Surya. -
Resizing columns in a JTable in a JScrollpane
I have a JTable in a JScrollpane and I after I load the table, I resize the columns to fit the data (works well).
The problem is that I want the scrollpane to stay the same size and let the table scroll horizontally inside the viewport. The actual result is the scrollpane stretches to the width of the table causing the user to scroll the panel rather than the scrollpane.
I've tried setting the scrollbar policy but that didn't work.I am passing the JTable to the constructor of the JScrollPane.
I have a JTable in a JScrollPane that sits on a JPanel which is in a JScrollPane itself.
After I load the data into the JTable, I resize all of the columns to fit the data.
The problem is that the JTable resizes wider than original size causing the whole panel to scroll horizontally. I would rather have the JScrollPane that the JTable is in scroll. -
Set multi user column with PowerShell used to work in 2010 but no longer works in 2013
In SharePoint 2010 I used PowerShell to set the value of multi user people columns and it worked really well. I attempt to use the same PowerShell to set the same column type in SharePoint 2013 and it fails.
here is the PowerShell that I use in 2010:
$web = Get-SPWeb "http://intranet"
$list = $web.lists["TestList"]
$item = $list.items.add()
$item["Title"] = "Test multi user column"
$users = @("Domain\user1", "Domain\user2")
$userList = new-object Microsoft.SharePoint.SPFieldUserValueCollection
foreach($user in $users)
$spUser = $web.EnsureUser($user)
$userValue = new-object Microsoft.SharePoint.SPFieldUserValue($web, $spUser.ID, $spUser.Name)
$userList.Add($userValue)
$item["MultiUserColumn"] = $userList
$item.update()
I have used this on three SharePoint 2013 farms with differing results. On two of them I receive an error when running $item.update(): Exception calling "Update" with "0" argument(s): "Invalid look-up value. A look-up
field contains invalid data. Please check the value and try again."
If I take one of the users out of the $users list then it works fine, but it will not allow multiple users to be set with PowerShell. I can use the GUI to add more than one user but not PowerShell.
Does anyone know if these methods have changed in 2013? I haven't been able to find anyone else with this issue.
mmm... coffee...Not sure but maybe something to do with casting. Below is the code snippet from one of the blogs. Try modifying your script like below and see if still you get the error
[Microsoft.SharePoint.SPFieldUserValueCollection]$lotsofpeople = New-Object Microsoft.SharePoint.SPFieldUserValueCollection
$user1 = $w.EnsureUser("domain\user1");
$user1Value = New-Object Microsoft.SharePoint.SPFieldUserValue($w, $user1.Id, $user1.LoginName)
$user2 = $w.EnsureUser("domain\user2");
$user2Value = New-Object Microsoft.SharePoint.SPFieldUserValue($w, $user2.Id, $user2.LoginName);
$lotsofpeople.Add($user1Value);
$lotsofpeople.Add($user2Value);
$i["lotsofpeoplefield"] = $lotsofpeople;
$i.Update();
#-or-
$l.Fields["lotsofpeoplefield"].ParseAndSetValue($i,$lotsofpeople);
$i.Update();
Reference to the link
http://social.technet.microsoft.com/wiki/contents/articles/20831.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-powershell.aspx
Geetanjali Arora | My blogs | -
Add column with preq number to ALV grid in me53n
hi all,
i am trying to add column with preq number (BANFN) to ALV with preq items in ME53N. it is not available in column set, when trying to add by "change layout" button - i dont understand why, when the strcucture MEREQ3211GRID contains it :-(
i also tried to add new field ZZBANFN into the structure CI_EBANMEM and after that, i could add the new field to ALV through change layout, but it was empty of course. so i implemented EXIT_SAPLMEREQ_001 from MEREQ001, but ZZBANFN is still empty, because this exit is not called when opening ME53N, but when clicking on tab "customer data" in preq item detail.
how to solve this? is there any exit that is called before displaying the ALV grid?Here is some more detail. I included my code from the Enhancement.
ENHANCEMENT-POINT MM06EFPO_POT_AUFBAUEN_02 SPOTS ES_MM06EFPO_POT_AUFBAUEN INCLUDE BOUND.
ENHANCEMENT 1 Z_MM06EFPO_POT_AUFBAUEN_1. "active version
SELECT SINGLE zz_old_material FROM mara
INTO pot-zz_old_material
WHERE matnr = pot-matnr.
ENDENHANCEMENT.
You will also need to change the layout in Item Overview to bring your field in. -
Resize column width for JTable without column headers?
Hi,
I find that for me to resize columns of a JTable by using
mouse dragging, I MUST have column headers and then drag
column headers to resize them. Is my understanding correct?
Actually, I need to have a table without header columns.
How can I use mouse to resize column width by dragging?
The background for this request is that I am putting a
complex table as another table's column header and I hope to
be able to resizing the complex table by mouse dragging.
Thanks very much,
DavidHi,
I think you have mistake there. Try
<style type="text/css">
table.apexir_WORKSHEET_DATA td {
white-space:nowrap !important;
td[headers="DESCR"] {
width:300px !important;
max-width:300px !important;
#apexir_DESCR {
width:10px;
max-width:300px !important;
</style>And you can try add
table.apexir_WORKSHEET_DATA {
width: 100% !important;
table-layout: fixed !important;
}Regards,
Jari
My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
Twitter: http://www.twitter.com/jariolai -
Updates to JTables and resizing of columns
I'm building an application that has many tables that all use table models that I have created. All of the table models extend DefaultTableModel. Before entering any data in the tables i set the size of the columns. Below is an example of how I do this...
//tcm = table column model
tcm.getColumn(0).setPreferredWidth(100);
tcm.getColumn(1).setPreferredWidth(100);
tcm.getColumn(2).setPreferredWidth(100);
tcm.getColumn(3).setPreferredWidth(100);
tcm.getColumn(4).setPreferredWidth(172);
tcm.getColumn(5).setPreferredWidth(172);
My problem is everytime I update the table with new data the columns keep adjusting themselves to the width of the largest piece of data in the particular column. In order to keep the size of the columns I want I've been resizing the columns with the above code everytime I update the table. Can someone tell me how to set the column sizes once and have them remain that way?I'm sorry to hear that you're having problems customising your Spotify for Mac application. I'm sure Spotify do value your custom and will take your suggestion to return this feature. For now, I think posting your idea in the Ideas forum would be best to get your idea out there and upvoted by fellow community members wishing for the return of this feature. You can submit your idea at: https://community.spotify.com/t5/forums/postpage/board-id/ideas_submissions Take care and let me know how it goes!
-
Hello,
I insert a JTable without header in a JTextPane. I'm able to resize the width of the columns with the mouse, but the JTable isn't resized. I call the method JTable.setWidth(int width); to set the start width.
Do anyone knows a solution ?
Thanks in advanceUsually a JTable is added in an JScrollPane. Please use setMinimumSize() or setPreferredSize() to set this pane the size you want it to start.
-
Hello All,
Is it possible to have a user input in ALV grid. I know there can be editable columns/cells but suppose the application demands an input field to be placed in ALV Grid where the user will enter some value.
Could someone please suggest if this can be done.
Regards
IndrajitHere's THE definitive way to do it.
This little proggy demonstrates the following.
1) Create a DYNAMIC FCAT for an internal table with USER defined fields (i.e non ddic) and colour some columns in the FCAT.
2) Create a DYNAMIC TABLE.
3) Define a subclass of CL_GUI_ALV_GRID so you can access some very useful protected methods and attributes - you can get original and changed table IN ROWS which is a lot easier sometimes than messing around with individual
cells.
4) Create extra buttons on the toolbar.
5) Define EVENT handlers including data change so you can get control when the user enters data. YOU DON'T NEED PAI anymore with event handlers.
6) Call methods in your subclass of CL_GUI_ALV_GRID (you can also call methods in CL_GUI_ALV_GRID by virtue of Inheritance) from methods in your event handler class.
7) Display an editable Grid.
This method will work for almost any conditions you need to use.
I'm sure this covers all the bases -- please reply if any queries.
Run the program, click on the EDIT button and enter your data. Press ENTER when done.
All you need to do is copy this code and create one empty screen (SE51) with a custom container called CCONTAINER1 with the following logic in it.
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
(In the program you don't actually do anything in the PAI as the event handler takes care of this)
Now here's the program
PROGRAM zdynfieldcat.
class zcltest definition deferred. "For field symbol reference.
Simple test of dynamic ITAB with user defined (not ddic) fields
Build dynamic fcat
Table structure obtained via new RTTI functionality
use ALV grid to display and edit.
Create a blank screen 100 with a custom container called CCONTAINER1.
Define field symbols as these can't be defined in classes
field-symbols: <dyn_table> type standard table,
<g2> type ref to zcltest,
<g1> type ref to cl_gui_custom_container,
<actual_tab> type standard table,
<outtab> type table,
<fs1> type ANY,
<FS2> TYPE TABLE,
<fs3> type table,
<fs4> type table,
<fs5> type table.
class zcltest definition inheriting from cl_gui_alv_grid.
define this as a subclass so we can access the protected attributes
of the superclass cl_gui_alv_grid
public section.
types: g4 type ref to cl_gui_custom_container.
types: g3 type ref to cl_alv_changed_data_protocol.
data: i_parent type g4,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
zog like line of lr_rtti_struc->components. "RTTI
types: struc like zog.
types: struc1 type table of struc.
methods:
constructor
importing i_parent type g4,
disp_tab
importing p_er_data_changed type g3,
create_dynamic_fcat
importing zogt type struc1
exporting it_fldcat type lvc_t_fcat.
Protected section.
data: stab type ref to data,
wa_it_fldcat type lvc_s_fcat,
c_index type sy-index.
endclass.
class zcltest implementation.
METHOD constructor.
CALL METHOD super->constructor
EXPORTING
i_appl_events = 'X'
i_parent = i_parent.
endmethod.
method disp_tab.
mt_outtab is the data table held as a protected
attribute in class cl_gui_alv_grid.
assign me->mt_outtab->* TO <outtab>. "Original data
assign p_er_data_changed->mp_mod_rows TO <FS1>.
stab = p_er_data_changed->mp_mod_rows.
assign p_er_data_changed->mt_inserted_rows to <fs3>.
assign p_er_data_changed->mt_deleted_rows to <fs4>.
assign p_er_data_changed->mt_mod_cells to <fs5>.
assign stab->* TO <fs2>.
do whatever you want with <outtab>
contains data BEFORE changes each time.
Note that NEW (Changed) table has been obtained
already by call to form
check_data USING P_ER_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
Entered data is in table defined by <fs2>
In this method you can compare original and changed data.
Easier than messing around with individual cells.
do what you want with data in <fs2> validate / update / merge etc
endmethod.
method create_dynamic_fcat.
loop at zogt into zog.
c_index = c_index + 1.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
if c_index eq 2.
wa_it_fldcat-emphasize = 'C411'.
endif.
if c_index eq 3.
wa_it_fldcat-emphasize = 'C511'.
endif.
append wa_it_fldcat to it_fldcat .
endloop.
endmethod. "create_dynamic_fcat
endclass. "zcltest IMPLEMENTATION
class lcl_grid_event_receiver definition.
public section.
note that zcltest inherits all of events etc from
class cl_gui_alv_grid so specify event handler for
zcltest.
methods:
handle_data_changed
for event data_changed of zcltest
importing er_data_changed,
toolbar
for event toolbar of zcltest
importing e_object
e_interactive,
user_command
for event user_command of zcltest
importing e_ucomm.
endclass.
class lcl_grid_event_receiver implementation.
method handle_data_changed.
code whatever required after data entry.
various possibilites here as you
can get back Cell(s) changed
columns or the entire updated table.
Data validation is also possible here.
Note here the field sybol <g2> contains our
instance of class zcltest so we can now
call any methods / access
attributes of that class from this method
in our event handler class.
call method <g2>->disp_tab
EXPORTING
p_er_data_changed = er_data_changed.
endmethod. "handle_data_changed
method toolbar.
data : ls_toolbar type stb_button.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EDIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Edit' to ls_toolbar-text.
move icon_change_text to ls_toolbar-icon.
move 'Click2Edit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'UPDA' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Update' to ls_toolbar-text.
move icon_system_save to ls_toolbar-icon.
move 'Click2Update' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Exit' to ls_toolbar-text.
move icon_system_end to ls_toolbar-icon.
move 'Click2Exit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
endmethod. "toolbar
method user_command.
case e_ucomm .
when 'EDIT'. "From Tool bar
perform set_input.
perform init_grid.
when 'UPDA'. "From Tool bar
perform refresh_disp.
perform update_table.
when 'EXIT'. "From Tool bar
leave program.
endcase.
endmethod. "user_command
endclass. "lcl_grid_event_receiver IMPLEMENTATION
program data
include <icon>.
define any old internal structure NOT in DDIC
types: begin of s_elements,
anyfield1(20) type c,
anyfield2(20) type c,
anyfield3(20) type c,
anyfield4(20) type c,
anyfield5(11) type n,
end of s_elements.
data: wa_element type s_elements,
wa_data type s_elements.
Note new RTTI functionality allows field detail
retrieval at runtime for dynamic tables.
data:
grid1 type ref to zcltest,
grid_handler type ref to lcl_grid_event_receiver,
c_dec2 type s_elements-anyfield5,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
ls_comp LIKE LINE OF lt_comp, "RTTI
zog like line of lr_rtti_struc->components, "RTTI
struct_grid_lset type lvc_s_layo,
l_valid type c,
new_table type ref to data.
types: struc like zog.
data: zogt type table of struc,
grid_container1 type ref to cl_gui_custom_container,
g_event_receiver type ref to lcl_grid_event_receiver,
ok_code like sy-ucomm,
i4 type int4.
start-of-selection.
call screen 100.
module status_0100 output.
if grid_container1 is initial.
create object grid_container1
exporting
container_name = 'CCONTAINER1'.
assign grid_container1 to <g1>.
create object grid1
exporting i_parent = grid_container1.
we need reference to this instance so we can use
Methods etc of zcltest class and alv (superclass)
in our event receiver class.
assign grid1 to <g2>.
create object grid_handler.
set handler:
grid_handler->user_command for grid1,
grid_handler->toolbar for grid1,
grid_handler->handle_data_changed for grid1.
Get the Internal table structure
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
Build field catalog just use basic data here
colour specific columns as well
zogt[] = lr_rtti_struc->components.
call method grid1->create_dynamic_fcat
EXPORTING
zogt = zogt
IMPORTING
it_fldcat = it_fldcat.
Create dynamic internal table and assign
to field symbol.
Use dynamic field catalog just built.
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = new_table.
assign new_table->* to <dyn_table>.
perform populate_dynamic_itab.
perform init_grid.
perform register_enter_event.
set off ready for input initially
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endif.
endmodule. "status_0100 OUTPUT
module user_command_0100 input.
*PAI not needed in OO ALV anymore as User Commands
are handled as events
*in method user_command.
we can also get control if any data was entered
and the ENTER is pressed by
raising an event.
Control then returns to method handle_data_changed.
endmodule. "user_command_0100 INPUT
form populate_dynamic_itab.
load up a line of the dynamic table
c_dec2 = c_dec2 + 11.
wa_element-anyfield1 = 'Tabbies'.
wa_element-anyfield2 = 'ger.shepards'.
wa_element-anyfield3 = 'White mice'.
wa_element-anyfield4 = 'Any old text'.
wa_element-anyfield5 = c_dec2.
append wa_element to <dyn_table>.
endform. "populate_dynamic_itab
form exit_program.
call method grid_container1->free.
call method cl_gui_cfw=>flush.
leave program.
endform. "exit_program
form refresh_disp.
call method grid1->refresh_table_display.
endform. "refresh_disp
form update_table.
The dynamic table here is the changed table
read from the grid
after user has changed it
Data can be saved to DB or whatever.
loop at <dyn_table> into wa_element.
do what you want with the data here
endloop.
switch off edit mode again for next function
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "update_table
form set_input.
i4 = 1.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "set_input
form switch_input.
if i4 = 1.
i4 = 0.
else.
i4 = 1.
endif.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "switch_input
form init_grid.
Enabling the grid to edit mode,
struct_grid_lset-edit = 'X'. "To enable editing in ALV
struct_grid_lset-grid_title = 'Jimbos Test'.
call method grid1->set_table_for_first_display
EXPORTING
is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
endform. "init_grid
form register_enter_event.
call method grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
Instantiate the event or it won't work.
create object g_event_receiver.
set handler g_event_receiver->handle_data_changed for grid1.
endform. "register_enter_event
Have fun with this
Cheers
jimbo -
ORA-01400 - not null column with default value and item with authorization
I've searched - I would think someone has run into this. APEX 3.0.0.00.20 - I've created a simple form on a table. One of the column is a not null column with a default value. I have a select list on that item, but it has security on it - authorization scheme. So, it checks the user and if that user isn't of the right role, it will not even display that item. However, APEX appears to still send in the column in its sql! So, the default value is useless, it sends in null each time. Even if I set the default at the Item level, I get null. Argg. That's got to be a bug...
In debug, I do not see the item listed at all. It's not used. That's fine - but why is it trying to insert the value? I would think it would leave it off??? I think because the item is associated with a database column. But, getting around this is ugly. Having to create a hidden item for each one, and then check to see if I need to take the list value... horrible. Any way to get around this???I should add - I guess I can always put my own custom process in to replace the DML. Just seems like a simple thing - if the value doesn't appear on the debug, isn't set with any default value... don't include it in the DML.
-
How to order an entire Report by a column with in a group...
Okay, I have a Group Above report, and I want to order the groupings by a column within the group. I am using a lexical parameter in place of the entire ORDER BY statement in the query, giving the user the capability to sort the report by any specific column, at runtime.
So, basically, this parameter allows for the ORDER BY to be dynamic; however, in the Data Model, I am required to designate at least one hard-coded break column, which overrides whatever column is designated by the user at runtime.
Any ideas how I can get around this?Hi Brice,
If you want just i single hard coded column in a group
then i think you can create summary column with counting
so you can say say a column that gives you just Serial no.
and rest of the thing as it is.
in this way you got your hard column and also Order by facility
that you want.
Hope that helps you.
Enjoy Oracle....
Maybe you are looking for
-
How many devices can I have on my network
I need to know how many devices I can have on my home network. I'm using the netgear wifi. 300mbps It seems to get really bogged down when I have 3 or more apple tv's going and iphone's, ipad's, etc.... Any suggestions?
-
ITunes keeps losing movie thumbnails
Hi I'm using iTunes on W7 Pro 64 bit, all been working fine until the v10 update. Ever since it has been having trouble remebering the poster frames I set for movies. Not all movies, just some - and I think only the ones imported after v10. I can set
-
Muliple inspection plan for same material and same usage
Hi, I need to create multiple inspection plans for same material with same usage.during the inspection lot creation i need to select any one inspection plan. In standard SAP its not possible.Any user exits available for this.. Regards, S.P.Selvathang
-
HT201210 i can not make update to version 7.1
there is massage the phone not found and the phone closed and not open
-
Capacity bar does not show detail in itunes
Capacity bar does not show detail in itunes 10 when iphone is connected via wifi when I connect via cable it corrects itself running os 5.01