Display Image in ALV
Hi Gurus,
Am developing ALV report using OOPS. In that i have to insert company logo. By using the below code it is coming good
CREATE OBJECT CONTAINER
EXPORTING
CONTAINER_NAME = 'PICTURE'.
CREATE OBJECT PIC
EXPORTING
PARENT = CONTAINER.
CALL METHOD pic->set_display_mode
EXPORTING
display_mode = CL_GUI_PICTURE=>DISPLAY_MODE_FIT_CENTER
EXCEPTIONS
ERROR = 1
others = 2
CALL METHOD pic->load_picture_from_url
EXPORTING
url = 'file://D:\kk.GIF'
IMPORTING
RESULT =
EXCEPTIONS
ERROR = 1
others = 2
But here am hardcoding the url of the logo. Instead of that upload the image into SAP and how to insert that logo in that screen? Can anyone give me suggestions regarding this.
Points will be awarded
Thanks
Ravi
Hi
In the transaction OAOR, you should be able to insert your company Logo.
GOTO - OAOR (Business Document Navigator)
Give Class Name - PICTURES Class Type - OT..... then Execute
It will show you the list, then select ENJOYSAP_LOGO.
On that list, you will find one control with a "create" tab.
Click std. doc types.
Select SCREEN and double-click.
It will push FILE selection screen.
Select your company logo (.gif) and press OK.
It will ask for a description- for instance: "company logo".
It will let you know your doc has been stored successfully.
You can find your logo under ENJOYSAP_LOGO->Screen->company logo.
Just run your ALV program, you should find your company logo in place of the EnjoySAP logo.
FORM TOP-OF-PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEADING[]
I_LOGO = 'ENJOYSAP_LOGO'
I_END_OF_LIST_GRID ='GT_LIST_TOP_OF_PAGE'.
ENDFORM. "TOP-OF-PAGE
Here 'ENJOYSAP_LOGO' will replace by ur created logo.
Refer this link
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_enhanced.htm
http://www.sap-img.com/abap/alv-logo.htm
http://www.sap-img.com/fu002.htm
Re: Logo on Login screen
Re: To change image into main menu of sap
Reward points for useful Answers
Regards
Anji
Similar Messages
-
WD4A : Displaying images in ALV table
Hi,
Does anyone know how to display images in ALV tables in Webdynpro?Hello,
You can define an attribute in the context with the type CHAR 30 and define it value like an icon from WDA (like ~Icon/GreenLed). And then you need to create an method to define the attributes of the column that will have the image like follows:
METHOD display_alv .
DATA: lr_alv_usage TYPE REF TO if_wd_component_usage,
lr_config TYPE REF TO cl_salv_wd_config_table,
lr_col_header TYPE REF TO cl_salv_wd_column_header,
lr_function_wd TYPE REF TO cl_salv_wd_function,
lr_button TYPE REF TO cl_salv_wd_fe_button,
lr_image TYPE REF TO cl_salv_wd_uie_image,
lr_header TYPE REF TO cl_salv_wd_header,
lr_uie_link TYPE REF TO cl_salv_wd_uie_link_to_action,
lr_if_controller TYPE REF TO iwci_salv_wd_table,
lr_function_set TYPE REF TO if_salv_wd_function_settings,
lr_table_settings TYPE REF TO if_salv_wd_table_settings,
lr_column_settings TYPE REF TO if_salv_wd_column_settings.
DATA: lt_columns TYPE salv_wd_t_column_ref,
ls_column TYPE salv_wd_s_column_ref,
lv_text TYPE string.
* Instantiate ALV Component
lr_alv_usage = wd_this->wd_cpuse_all_alv( ).
IF lr_alv_usage->has_active_component( ) IS INITIAL.
lr_alv_usage->create_component( ).
ENDIF.
* get reference to model
lr_if_controller = wd_this->wd_cpifc_all_alv( ).
lr_config = lr_if_controller->get_model( ).
* modify visible rows
lr_config->if_salv_wd_table_settings~set_visible_row_count( iv_rows ).
lr_config->if_salv_wd_table_settings~set_selection_mode(
wd_assist->co_alv_selmode ).
* create function
lr_function_set ?= lr_config.
lr_function_wd = lr_function_set->create_function(
wd_assist->co_func_det_nfe ).
CREATE OBJECT lr_button.
*read text
lv_text = wd_assist->read_text( iv_key = '002' ).
lr_button->set_text( lv_text ).
lv_text = wd_assist->read_text( iv_key = '001' ).
lr_button->set_tooltip( lv_text ).
lr_button->set_image_source( wd_assist->co_icon_seldet ).
lr_function_wd->set_editor( lr_button ).
* set table header
lr_table_settings ?= lr_config.
lr_header = lr_table_settings->get_header( ).
lv_text = wd_assist->read_text( iv_key = '003' ).
lr_header->set_text( lv_text ).
lv_text = wd_assist->read_text( iv_key = '004' ).
lr_header->set_tooltip( lv_text ).
lr_header->set_image_source( wd_assist->co_icon_list ).
lr_column_settings ?= lr_config.
lt_columns = lr_column_settings->get_columns( ).
LOOP AT lt_columns INTO ls_column.
CASE ls_column-id.
WHEN 'ICON'.
CREATE OBJECT lr_image.
lr_image->set_source_fieldname( ls_column-id ).
lr_image->set_tooltip_fieldname( 'ICON_TOOLTIP' ).
ls_column-r_column->set_cell_editor( lr_image ).
WHEN 'ID'.
CREATE OBJECT lr_uie_link.
lr_uie_link->set_text_fieldname( ls_column-id ).
ls_column-r_column->set_cell_editor( lr_uie_link ).
WHEN 'ICON_TOOLTIP' or 'LOGSYS'.
ls_column-r_column->set_visible(
cl_wd_uielement=>e_visible-none ).
ENDCASE.
*set header binding of medium description, otherwise title
lr_col_header = ls_column-r_column->get_header( ).
lr_col_header->set_ddic_binding_field(
if_salv_wd_c_column_settings=>ddic_bind_medium ).
ENDLOOP.
ENDMETHOD.
Here will be showed an icon (column ICON) and an link (column ID).
Regards, -
To Display Image in Alv Grid....
Hello Gurus,
I want to display an image/icon ( custom icon ) in the ALV grid.
I know to display standard icons in ALV. But i dont know how to store custom icons in the system.
I want to display an icon or image depending upon certain conditions. i need to display these images/icons for each row of the ALV grid.
Please let me know if i can show images or icons ( not standard ) for each row in ALV grid.
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Feb 25, 2008 10:20 AMcheck out CL_GUI_PICTURE and the demo programs
SAP_PICTURE_DEMO
SAP_PICTURE_DEMO_ICON
RSDEMO_PICTURE_CONTROL
you can fit the picture in to the control with the following modes.
DISPLAY_MODE_FIT
other options
DISPLAY_MODE_NORMAL
DISPLAY_MODE_STRETCH
DISPLAY_MODE_NORMAL_CENTER
DISPLAY_MODE_FIT_CENTER
Regards
Raja -
How to display image on alv display screen
Hi All,
I am using "REUSE_ALV_GRID_DISPLAY" function module for display a simple report.
I want to add a logo also on that output screen. Can anyone tell me how i can do that?
Thanks and Regards,
Nidhi Srivastava.Yes.
But you have to paint the image after the native component has painted the text, to avoid the native component from erasing your image. Something like this should work.
class MyTextField extends TextField implements Runnable
public void paint(Graphics g)
super.paint(g);
new Thread(this).start();
public void run()
Thread.yield();
Graphics g = getGraphics();
g.drawImage(....) -
Display legend(as image) for ALV
Hello experts,
I have created ALV report in which it displays data in ALV grid. I want to display legend as image which explain output of the ALV grid. ie I want to display image below/under the ALV, which image gives information about outpout. (Legend)
Any suggestions or helpful solutions ideas are appreciated.
Thanks in advance...
Regards,
Viral Patel
Edited by: Viral Patel on Jan 5, 2010 6:24 AMHi Sandeep,
Thanks for Your quick response.
Could You please elaborate it how can I implement it in my code as I am new to ALV. There is one button in ALV display called 'Information(Ctrl+F12), when I press it will open browswer and display help on ALV. Is there any way to customize that button and get display legend?
Thanks n Regards,
Viral Patel
Edited by: Viral Patel on Jan 5, 2010 6:42 AM -
Display image in classical report
Experts,
Please share how to display image stored in SO10 in to a classical report??Hi
check this
In the transaction OAOR, you should be able to insert your company Logo.
GOTO - OAOR (Business Document Navigator)
Give Class Name - PICTURES Class Type - OT..... then Execute
It will show you the list, then select ENJOYSAP_LOGO.
On that list, you will find one control with a "create" tab.
Click std. doc types.
Select SCREEN and double-click.
It will push FILE selection screen.
Select your company logo (.gif) and press OK.
It will ask for a description- for instance: "company logo".
It will let you know your doc has been stored successfully.
You can find your logo under ENJOYSAP_LOGO->Screen->company logo.
Just run your ALV program, you should find your company logo in place of the EnjoySAP logo.
FORM TOP-OF-PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEADING[]
I_LOGO = 'ENJOYSAP_LOGO'
I_END_OF_LIST_GRID ='GT_LIST_TOP_OF_PAGE'.
ENDFORM. "TOP-OF-PAGE
Here 'ENJOYSAP_LOGO' will replace by ur created logo.
Refer this link
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_enhanced.htm
http://www.sap-img.com/abap/alv-logo.htm
http://www.sap-img.com/fu002.htm
Re: Logo on Login screen
Re: To change image into main menu of sap
Regards
Anji -
How to display image and data in module pool screen?
Hi,
I want to display image and relevant data besides the image in module pool screen, I am using docking container to display the image.
Actually I am able to display image or data any one but not both.
one more thing I want to display multiple images and their data.
Please suggest some one if you have any idea.
Regards,
Dileep.You can try below way, I have used in report.
DATA: gc_docking TYPE REF TO cl_gui_docking_container, "#EC NEEDED "Docking Container
gc_split TYPE REF TO cl_gui_easy_splitter_container, "#EC NEEDED "Splitter
gc_top_container TYPE REF TO cl_gui_container, "#EC NEEDED "Top Container
gc_bottom_container TYPE REF TO cl_gui_container, "#EC NEEDED "Bottom Container
gc_document TYPE REF TO cl_dd_document, "#EC NEEDED "Document
gc_events TYPE REF TO lcl_event_class, "#EC NEEDED " Local Event Class
gc_grid TYPE REF TO cl_gui_alv_grid, "#EC NEEDED " ALV Class
" Creating Docking
CREATE OBJECT gc_docking
EXPORTING
ratio = c_95.
IF sy-subrc EQ 0.
* Splitting the Docking container
CREATE OBJECT gc_split
EXPORTING
parent = gc_docking
sash_position = c_10 "Position of Splitter Bar (in Percent)
with_border = c_1. "With Border = 1 Without Border = 0
ENDIF.
* Placing the containers in the splitter
gc_top_container = gc_split->top_left_container .
gc_bottom_container = gc_split->bottom_right_container .
* Creating Grid
CREATE OBJECT gc_grid
EXPORTING
i_parent = gc_bottom_container.
ELSE.
* Background job handling
CREATE OBJECT gc_grid
EXPORTING
i_parent = gc_docking.
ENDIF.
* Creating the document
CREATE OBJECT gc_document
EXPORTING
style = 'ALV_GRID'.
Regards,
Sameer -
Can We Display Image on Hieararichal Report on Each Line item
Dear Gurus ,
I have a Strange Requirement from the Client . They want to display Image on each line item of report with regard to Material in Hierarchal Sequential Report . Is there any solution for the same .
Thanks in advance
regards
ShankarI am having a path which is stored in SAP database which i have fetched in the reported in both alv heriarchal and also in Alv Grid . The Image is stored from DMS . Now what i am doing is i am trying to load a excel file from program BCALV_BDS_UPLOAD and when i run my report and go to view and select Microsoft Excel option the I am getting an error Bad file format .
The Path is : SAPR3://SAPR3CMS/get/200/DMS_5FC1/DE72B28A5B76F0F1AF0000215E54283E/FM1E1085XX18W-001E.jpg
Can you please help me out in this .
Regards
Shankar -
How to Display Logo in ALV Header?
Hi
I want to display/ print my company logo image in ALV Header. Please help me how can I do this?
Thanks
Iftikhar Ali
Islamabad.Hi,
If you are already having a logo say ZLOGO .
You can use it this way .
Give TOP-OF-PAGE
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
i_save = 'X'
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
And in top of page do this .
FORM top-of-page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRIT
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHE
i_logo = 'ZLOGO'
I_END_OF_LIST_GRID =
endform.
Hope this will work .
Reward if found useful.
Regards
SureshP. -
Not able to display logo on alv grid output
hi
can anybody guide me.
i have written code for displaying logo on alv grid report.
i uploaded bmp image using OAER
but even then i am not able to display logo on the report please help me
i am using 4.7 version..
code...
REPORT ZALVLOGO .
type-pools: slis.
data: i_sflight type table of sflight.
*data: begin of i_sflight occurs 10.
*include structure sflight.
*data: end of i_sflight.
data: it_events type slis_t_event,
wa_events type slis_alv_event.
select * from sflight into table i_sflight.
perform form_fill_table.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_TOP_OF_PAGE = 'top-of-page'
I_STRUCTURE_NAME = 'sflight'
TABLES
T_OUTTAB = i_sflight
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.
*& Form top_of_page
text
--> p1 text
<-- p2 text
FORM top-of-page .
data: t_header type slis_t_listheader,
wa_header type slis_listheader.
wa_header-typ = 'h'.
wa_header-info = 'FLIGHT DETAILS'.
APPEND wa_header to t_header.
CLEAR WA_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = t_header
I_LOGO = 'ENJOY'.
I_END_OF_LIST_GRID =.
ENDFORM. " top_of_page
*& Form form_fill_table
text
--> p1 text
<-- p2 text
FORM form_fill_table .
clear wa_events.
wa_events-name = 'top-op-page1'.
wa_events-form = 'top-of-page'.
append wa_events to it_events.
ENDFORM. " form_fill_tablehi ,
First upload images in SAP using transaction se78
http://www.howforge.com/step-by-step-upload-bitmap-images-to-sap
Then use that Image name to call using function module
in top of -page
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
i_logo = 'KAL1_LOGO'
it_list_commentary = lt_top_of_page_no_sel.
Regards
Deepak. -
hi,
I want to display images ( own photos) dynamically in ALV WDYnot in a table...
How can i do that?
Kindly help me to come out from this scenariao
Thanks in Advance...
Vimal rajHI
Store the image in the mime repository of the web dynpro component.
add one more attibute to the mode which is bound to the mapped to the data node of ALV comp.
type string.
then fill the mode again with this attirbute having the URL for the mime image object.
here is the sample code for that.
DATA lt_zdealer TYPE wd_this->Elements_zdealer.
DATA ls_zdealer LIKE LINE OF lt_zdealer.
data indx type i.
** @TODO compute values
** e.g. call a data providing FuBa
data url type string.
url = '/SAP/BC/WebDynpro/SAP/ZSSG_FEB_EXPL4/'.
DATA URL1 TYPE STRING.
loop at lt_zdealer into ls_zdealer.
indx = sy-tabix mod 3.
if indx eq 0.
CONCATENATE URL 'Blue hills.jpg' INTO URL1.
ls_zdealer-Imageurl = URL1.
elseif indx eq 1.
CONCATENATE URL 'Sunset.jpg' INTO URL1.
ls_zdealer-imageurl = URL1.
else.
CONCATENATE URL 'Winter.jpg' INTO URL1.
ls_zdealer-imageurl = URL1.
endif.
url1 = ''.
modify lt_zdealer from ls_zdealer.
endloop.
** bind all the elements
node->bind_table(
new_items = lt_zdealer
set_initial_elements = abap_true ).
then go to the place where you are producing the alv.
if it is opening in the intitial screen itself, then get the model of the ALV and change the editor and set it to image and set the
source of this editor to that attribute.
here is the sample code.
data lo_cmp_usage type ref to if_wd_component_usage.
lo_cmp_usage = wd_this->wd_cpuse_alv( ).
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
lo_INTERFACECONTROLLER = wd_this->wd_cpifc_alv( ).
DATA lo_value TYPE ref to cl_salv_wd_config_table.
lo_value = lo_interfacecontroller->get_model(
data col type ref to CL_SALV_WD_COLUMN.
col = lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'IMAGEURL' ).
data image type ref to cl_salv_wd_uie_image.
CREATE OBJECT image.
image->SET_SOURCE_FIELDNAME( 'IMAGEURL' ).
COL->SET_CELL_EDITOR( image ).
thanks
sarbjeet singh -
Total is not getting displayed in the ALV output.
Hi,
Total is not getting displayed in the ALV output.
I m using :REUSE_ALV_BLOCK_LIST_APPEND & REUSE_ALV_BLOCK_LIST_DISPLAY
Are there any issues with it as the same settings are working fine with REUSE_ALV_LIST_DISPLAY
source code:
DATA: layout TYPE slis_layout_alv,
IT_eventS TYPE slis_t_event,
fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
rec_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
TYPES: BEGIN OF ty_tab,
belnr TYPE dberchz-belnr,
belzart TYPE dberchz-belzart,
net TYPE dberchz-nettobtr,
END OF ty_tab.
DATA: lt_tab TYPE STANDARD TABLE OF ty_tab.
SELECT belnr belzart nettobtr
FROM dberchz
INTO TABLE lt_tab[]
WHERE belnr eq '000000000001'.
if sy-subrc ne 0.
ENDIF.
* defining layout
layout-colwidth_optimize = 'X'.
layout-def_status = 'X'.
*defning event
*event
*defining field catalog
fcat-col_pos = 1.
fcat-fieldname = 'BELNR'.
fcat-tabname = 'LT_TAB'.
APPEND fcat.
fcat-col_pos = 2.
fcat-fieldname = 'BELZART'.
fcat-tabname = 'LT_TAB'.
APPEND fcat.
fcat-col_pos = 3.
fcat-fieldname = 'NET'.
fcat-tabname = 'LT_TAB'.
fcat-do_sum = 'X'.
APPEND fcat.
*calling alv
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = 'YZ_PLR'
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = layout
it_fieldcat = fcat[]
i_tabname = 'LT_TAB'
it_events = IT_EVENTS[]
* IT_SORT =
* I_TEXT = ' '
tables
t_outtab = lt_tab[]
* EXCEPTIONS
* PROGRAM_ERROR = 1
* MAXIMUM_OF_APPENDS_REACHED = 2
* OTHERS = 3
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
Thanks,
GauravHi
No I don't think, this is my code (based on your code) and it works fine:
TYPE-POOLS SLIS.
DATA: BEGIN OF LT_TAB OCCURS 0,
BELNR LIKE BSEG-BELNR,
GJAHR LIKE BSEG-GJAHR,
WRBTR LIKE BSEG-WRBTR,
WAERS LIKE BKPF-WAERS,
END OF LT_TAB.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV,
IT_EVENTS TYPE SLIS_T_EVENT,
FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
REC_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
START-OF-SELECTION.
FCAT-COL_POS = 1.
FCAT-FIELDNAME = 'BELNR'.
FCAT-TABNAME = 'LT_TAB'.
FCAT-REF_FIELDNAME = 'BELNR'.
FCAT-REF_TABNAME = 'BSEG'.
APPEND FCAT.
FCAT-COL_POS = 2.
FCAT-FIELDNAME = 'GJAHR'.
FCAT-TABNAME = 'LT_TAB'.
FCAT-REF_FIELDNAME = 'GJAHR'.
FCAT-REF_TABNAME = 'BSEG'.
APPEND FCAT.
FCAT-COL_POS = 3.
FCAT-FIELDNAME = 'WRBTR'.
FCAT-TABNAME = 'LT_TAB'.
FCAT-CFIELDNAME = 'WAERS'.
FCAT-REF_FIELDNAME = 'WRBTR'.
FCAT-REF_TABNAME = 'BSEG'.
FCAT-DO_SUM = 'X'.
APPEND FCAT.
FCAT-COL_POS = 4.
FCAT-FIELDNAME = 'WAERS'.
FCAT-TABNAME = 'LT_TAB'.
FCAT-REF_FIELDNAME = 'WAERS'.
FCAT-REF_TABNAME = 'BKPF'.
FCAT-DO_SUM = SPACE.
APPEND FCAT.
SELECT * FROM BSEG INTO CORRESPONDING FIELDS OF TABLE LT_TAB
WHERE BUKRS = 'MAAB'
AND BELNR = '0000000001'.
LT_TAB-WAERS = 'EUR'.
MODIFY LT_TAB FROM LT_TAB TRANSPORTING WAERS WHERE WAERS = SPACE.
*CALLING ALV
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = 'ZPROVAMAX5'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = LAYOUT
IT_FIELDCAT = FCAT[]
I_TABNAME = 'LT_TAB'
IT_EVENTS = IT_EVENTS[]
TABLES
T_OUTTAB = LT_TAB[].
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
I've also inserted a currency field
Max -
Open and display image in MVC layout
Hello!
I cant figure out how I shall do this in an MVC layout:
The program request user to open an image file that are then displayed in a JLabel
My setup at the moment resolve in a nullpointerexeption because it dont get any actual image file, but I dont understand what I have missed.
I can not post the whole code fo you to run because it is to big, so I post the part that are the most important. please have a look.
PicturePanel
//Import Java library
import javax.swing.*;
import java.awt.*;
public class PicturePanel extends JPanel {
//Variables
private ImageIcon picture;
//Method to get information of the selected file
PicturePanel (String fileName) {
picture = new ImageIcon (fileName); //Get the filename
int w = picture.getIconWidth(); //Get the image with
int h = picture.getIconHeight(); //Get the image height
//Set preferable size for the image (Use the properties for the selected image)
setPreferredSize(new Dimension(w, h));
setMinimumSize(new Dimension(w, h));
setMaximumSize(new Dimension(w, h));
//Method to draw the selected image
protected void paintComponent(Graphics g) {
super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
}From my model:
//Local attributes
boolean check = false; //Used to see if a statement is true or not
PicturePanel pp;
JFileChooser fc;
int returnVal;
//newFile in File menu
public void newFile() {
//Open a file dialog in users home catalog
fc = new JFileChooser();
//In response to a button click:
returnVal = fc.showOpenDialog(pp);
System.out.println("You pressed new in file menu");
}From my controler:
//User press "New" in File menu
else if (user_action.equals("New")) {
//Call method in model class
model.newFile();
//Update changes
if (model.returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("Hello1");
File f = model.fc.getSelectedFile();
if (model.pp != null)
model.pp = new PicturePanel(f.getAbsolutePath());
System.out.println("Hello2");
//Display image (Here is line 83)
view.setImage_DisplayArea(model.pp);
System.out.println("Hello3");
}From my view:
//Sets the image to be displayed on the image_display area (Here is line 302)
public void setImage_DisplayArea(PicturePanel pp) {
image_display.add(pp);
}The complet error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1015)You pressed new in file menu
Hello1
Hello2
at java.awt.Container.add(Container.java:351)
at View_Inlupp2.setImage_DisplayArea(View_Inlupp2.java:302)
at Control_Inlupp2.actionPerformed(Control_Inlupp2.java:83)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:334)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1050)
at apple.laf.CUIAquaMenuItem.doClick(CUIAquaMenuItem.java:119)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1091)
at java.awt.Component.processMouseEvent(Component.java:5602)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3129)
at java.awt.Component.processEvent(Component.java:5367)
at java.awt.Container.processEvent(Container.java:2010)
at java.awt.Component.dispatchEventImpl(Component.java:4068)
at java.awt.Container.dispatchEventImpl(Container.java:2068)
at java.awt.Component.dispatchEvent(Component.java:3903)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
at java.awt.Container.dispatchEventImpl(Container.java:2054)
at java.awt.Window.dispatchEventImpl(Window.java:1801)
at java.awt.Component.dispatchEvent(Component.java:3903)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)Edited by: onslow77 on Dec 16, 2009 5:00 PM
Edited by: onslow77 on Dec 16, 2009 5:04 PMHello again!
Anyone that can help me figure out how to implement this in an MVC layout, I feel stuck.
I post a little program that open and display an image file so that you better can understand what I whant to do.
ShowImage
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.filechooser.*;
public class ShowImage extends JFrame{
//Variables
JFileChooser fc = new JFileChooser();
PicturePanel pp = null;
ShowImage () {
super("Show"); //Title
//Create the GUI
JPanel top = new JPanel();
add(top, BorderLayout.NORTH);
JButton openBtn = new JButton("Open");
top.add(openBtn);
openBtn.addActionListener(new Listner());
//Settings for the GUI
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
class Listner implements ActionListener {
public void actionPerformed(ActionEvent ave) {
int answer = fc.showOpenDialog(ShowImage.this);
if (answer == JFileChooser.APPROVE_OPTION){
File f = fc.getSelectedFile();
//Check
System.out.println(f);
System.out.println(pp);
if (pp != null)
remove(pp); //Clean so that we can open another image
//Check
System.out.println(pp);
//Set the PicturePanel
pp = new PicturePanel(f.getAbsolutePath());
//Check
System.out.println(pp);
//Add PicturePanel to frame
add(pp, BorderLayout.CENTER);
validate();
pack();
repaint();
//Main
public static void main(String[] args) {
new ShowImage();
}PicturePanel
//Import Java library
import javax.swing.*;
import java.awt.*;
public class PicturePanel extends JPanel {
//Variables
private ImageIcon picture;
//Method to get information of the selected file
PicturePanel (String fileName) {
picture = new ImageIcon (fileName); //Get the filename
int w = picture.getIconWidth(); //Get the image with
int h = picture.getIconHeight(); //Get the image height
//Set preferable size for the image (Use the properties for the selected image)
setPreferredSize(new Dimension(w, h));
setMinimumSize(new Dimension(w, h));
setMaximumSize(new Dimension(w, h));
//Method to draw the selected image
protected void paintComponent(Graphics g) {
super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
}//The endEdited by: onslow77 on Dec 16, 2009 7:30 PM -
Hi everyone, I am a newbie for labview. I just wanna ask you about image display in labview. Now I can display one image in my front panel. I open the file path and display it. First thing I wanna do is that is it possible to display on monitor full screen not on front panel and second thing is that how can I display images in folder and display it about 2 seconds delay in between? Pls kindly help me.
Thanks millions.
Solved!
Go to Solution.Hi there,
-I don't know whether the image full display can be possible or not, Any reason why you are asking for such requirement?
-The other question about reading files in a folder and display for 2sec can be done like shown in image.
-I've attached vi in lv 12 if needed.
-Next time, please post your vision related queries in Machine vision Board.
Thanks
uday,
Please Mark the solution as accepted if your problem is solved and help author by clicking on kudoes
Certified LabVIEW Associate Developer (CLAD) Using LV13
Attachments:
Image_read_folder.vi 43 KB -
Display image in java.awt.List
hello guys,
How i can display image in java.awt.List means listbox. give me sample code. if you have
Waiting for your favorable reply.
Regards,
Bhavesh Kharwajava.awt.List you can not.
javax.swing.JLast you can.
Maybe you are looking for
-
OS9 Premiere v6.0 & Cleaner v5.1.2 freezing system
I've just freed up my G4 Dual 1Ghz due to a newer Mac and wanted it put it to use running Premiere v6.0 and Cleaner v5.1.2 which is currently handled by an even older Beige G3 (with 800Mz processor) but of course has a lot slower bus speed. The G4 ha
-
Urgent ... Pl help..query misbehaves...
Hi all, my query forces to use trim in join conditions when i retrive rows in bulk. but am getting proper results if am retriving few rows without trim in join conditions.what could be the problem . am using 9.2.0.1.0/win2k regds kt
-
Selling powermac G4 with display
Hello, We are going to sell (2) Powermac G4 with OSX 768mb DDR SDRAM, 60HD with (2) 20" Displays. How much roughly should we be asking for? Both the computer and display are in good condition and will be wiped clean. Thanks
-
9i - calling reports from menu
Hi, Could somebody tell me if it's possible to call a report using the run_report_object facility from a menu. There isn't the reports node that there is on a form to define the report. Many thanks, Sean Dwyer
-
Unable to connect to OVD using the odsm
Hi All, I was unable to connect to the OVD 11.1.1.3.0 installed using the ODSM, while i was able to connect to the OID happily. I tried to connect to the OVD using the adminssl port (8899), non-ssl port (6501), ssl port (7501). I have the user id as