How do I assign images to grid cells based on their random number value?
Hello everyone!
I need a good point (or shove) in the correct direction.
Background
I've created (with previous help from this forum) a 12 x 9 random number grid which cycles through the numbers 1 to 9 a total of twelve times each. I've then created a button which shuffles the current grid's cells each time it is clicked. I now want to use 9 images that I have imported as individual symbols into the library (I have given them each their own class titled "skin1," "skin2," ... "skin9") as cell labels or the equivalent. I have also set the images up as individual movie clips (using the .Sprite class as the extended base class but keeping the actual image class names in line with their object name, i.e. the "skin1" image is the "skin1.as" class).
Question
How do I assign these images to the grid cells based on their respective values (ranging from 1 to 9) and have them populate the grid each time I click the "shuffle" button? So for example, in my grid the numbers 1 through 9 randomly appear 12 times each. Every time the number 4 appears in a cell, I want it to be assigned to the image "skin4" (which is just a graphic that looks like a button and has a fancy number "4" printed on it). Below is a chunk of the code I am using to draw the grid cells with:
// Creates a grid cell when called by generateGrid().
private funciton drawCell(_numeral:int):Sprite
This is the code I am currently implementing to populate the grids with (although I
don't want to use text labels as I want to fill each grid with an image according
to its numerical value (1 to 9).
var _label:TextField = new TextField();
_label.multiline = _label.wordWrap = false;
_label.autoSize = "center";
_label.text = String(_numeral);
// Add numerical label to cell array.
cellLabels.push(_label);
var _s:Sprite = new Sprite();
_s.graphics.lineStyle(2, 0x019000);
_s.graphics.drawRect(30, 0, cellW, CellH);
_s.addChild(_label);
return _s;
While the following isn't working code, it will hopefully demonstrate what I want to achieve inside this function so I don't have to use the above snippet for text labels:
//This will "hopefully" create an array of all 9 images by calling their classes. var _imageArray:Array = [skin1, skin2, skin3, skin4, skin5 , skin6, skin7, skin8, skin9]; // This is what I want to happen for each cell using the above image array: for (i = 0; i < cells; i++) { if (_numeral == 1) { // Insert skin1 image for each instance of #1 in the grid. } if (_numeral == 2) { // Insert skin2 image for each instance of #2 in the grid. } ... if (_numeral == 9) { // Insert skin9 image for each instance of #9 in the grid. } }
Again, I don't want to use text labels. I have a custom skin graphic that I want to go over each number on the grid based on its numerical value (1 to 9). Any help with this is much appreciated!
kglad,
Thank you for your help with this one. Using the code below, I have successfully populated my grid cells with the desired corresponding graphics. I noticed one thing though regarding my use of the shuffle button with this particular implementation: even though the numerical values residing in each cell get shuffled, the original images remain in the grid rather than being replaced by new ones. The first code snippet below is the revised cell drawing function including your help; the second snippet shows you my simple shuffle button function (where the problem lies, I think).
Snippet #1:
// Creates a grid cell when called by generateGrid().
private function drawCell(_numeral:int):Sprite
var _label:TextField = new TextField();
_label.multiline = _label.wordWrap = false;
_label.autoSize = "center";
// Creates a label that represents the numerical value of the cell.
cellLabels.push(_label);
var _s:Sprite = new Sprite();
_s.graphics.lineStyle(2, 0x019000);
_s.graphics.drawRect(30, 0, cellW, cellH);
// Physically adds the labels to the grid.
_s.addChild(_label);
// Assigns a graphic class to a cell based on its numerical value.
var _classRef:Class = Class(getDefinitionByName("skin" + _numeral));
// Undefined variable for holding graphic classes.
var _image:* = new _classRef();
// Lines the images up with the grid cells.
_image.x = 30;
// Physically adds a graphic on top of a cell label.
_s.addChild(_image);
return _s;
So far so good (although I question needing text labels at all if they are just going to remain invisible underneath the images, but enough about that for now). This next part is the reason that the images won't shuffle with the cell values, I think.
Snippet #2:
// When shuffleButton is clicked, this event shuffles
// the number array and fills the cellLabels with the new values.
private function onButtonShuffleClick(e:MouseEvent):void
// Shuffles the number array.
shuffle(numbers);
// Verifies the array has been shuffled.
trace("After shuffle:", numbers);
// Loop replaces old cellLabels with new number array values.
for (var i:int = 0; i < cells; i++)
cellLabels[i].text = String(numbers[i]);
As you can see, it never replaces the original images that populate the grid. I tried using the _s.removeChild(image) function but that didn't work, nor would copying/pasting some of the code from snippet #1 directly into this function as it would cause another instance of the images to be placed over top of the existing ones rather than actually swapping them out. Any continued help here is greatly appreciated!
PS Is there a quicker method for posting code into these forums without having to type it all out by hand again (i.e. copy/paste or drag/drop from my .fla or Notepad file directly into this thread)?
Similar Messages
-
How can I assign image file name from Main() class
I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
Here is the Main class
import org.me.lib.MyJNIWindowClass;
public class Main {
public Main() {
public static void main(String[] args) {
MyJNIWindowClass mw = new MyJNIWindowClass();
mw.s = "clock.gif";
And here is the library class
package org.me.lib;
public class MyJNIWindowClass {
public String s;
ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
public MyJNIWindowClass() {
JLabel jl = new JLabel(image);
JFrame jf = new JFrame();
jf.add(jl);
jf.setVisible(true);
jf.pack();
I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
Thank you.Your problem is one of timing. Consider this simple example.
public class Example {
public String s;
private String message = "Hello, " + s;
public String toString() {
return message;
public static void main(String[] args) {
Example ex = new Example();
ex.s = "world";
System.out.println(ex.toString());
}When this code is executed, the following happens in order:
1. new Example() is executed, causing an object to constructed. In particular:
2. field s is given value null (since no value is explicitly assigned.
3. field message is given value "Hello, null"
4. Back in method main, field s is now given value "world", but that
doesn't change message.
5. Finally, "Hello, null" is output.
The following fixes the above example:
public class Example {
private String message;
public Example(String name) {
message = "Hello, " + name;
public String toString() {
return message;
public static void main(String[] args) {
Example ex = new Example("world");
System.out.println(ex.toString());
} -
How to display tooltip in ALV GRID CELL?
Hello,
I'm trying to display dynamic tootips for data in ALV GRID Cells.
My ALV Gid Cells content does not display Icon or symbol or Exception but pure data (In my case dates).
Is there a way to do display a toolip that will change dynamicaly according to a rule.
I took a look at the BCALV_DEMO_TOOLTIP program
but it does not answer my expectation since it display
toltip for Icon or symbol or Exception.
Can someone help on this case.
Best regards
HarryHai Harry
icon
value set: SPACE, 'X' 'X' = column contents to be output as an icon.
The caller must consider the printability of icons.
symbol
value set: SPACE, 'X' 'X' = column contents are to be output as a symbol.
The internal output table column must be a valid symbol character.
The caller must consider the printability of symbols.
Symbols can usually be printed, but may not always be output correctly, depending on the printer configuration.
Thanks & regards
Sreenu -
How to set background image in a cell?
I am trying somethign that seems tricky to me...
The image I am using I faded to a solid color on the bottom
half. I set the background image to to left and NO REPEAT but when
the cell grows with content and it stretched beyond the image it
goes blank underneath. How do I set a background color without
going over the background image?
I need them both to be background because I want to use text
over both.
Any ideaS?Color goes UNDER the background image. Just set it.
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"StarPilot06" <[email protected]> wrote in
message
news:eqqve6$341$[email protected]..
>I am trying somethign that seems tricky to me...
>
> The image I am using I faded to a solid color on the
bottom half. I set
> the
> background image to to left and NO REPEAT but when the
cell grows with
> content
> and it stretched beyond the image it goes blank
underneath. How do I set
> a
> background color without going over the background
image?
>
> I need them both to be background because I want to use
text over both.
>
> Any ideaS?
> -
How to display an image in particular cell editor
Hi All,
I want to display an image as the background for the table cell.
I searched in sdn and found the solution only for link to action.
I have created a dynamic table and if i click on apply button one more row is getting added according to my requirement.
I want to differentiate this row from rest. So I need to display image for the last row in the table which is added newly.
Can anyone suggest the procedure for adding an image in a particular cell editor along with the table data?
Hope I am clear with my requirement.
Pls suggest.
Regards,
subashiniHi,
IF iam not wrong then for some rows u need to show text data and for some rows u need to show image data.
follow the following steps.
1. In ur table add cell editor of type Image.
2.Create a value node with one more than required attributes.
3.Suppose if need to show only one column then i will create
value node with two attributes.One attribute will be for text
data and one will for Image.
4.now access ur table cell editor dynamically.For image type
cell editor we need to play only with two properties source
and alt.Bind this alt property of editor wid that attribute which u
need use for text data and source wid that attribute which u
need to use for image.
5. Now suppose I need to show text data then
I will create one element of that value node.In case of Image
type cell editor source property is given prefrence over alt
property.
set attribute which is bound to alt to the actual text data
i.e setText("Actual text data");
and set attribute which is bound to source to some dummy
image name
i.e setImage("dummy.gif");
add this to node.
during execution as source property of editor is bound to
Image attribute of node which in turn is set to dummy value it
wont find actual source and will set Image cell editor with
watever is bound to alt property which in turn set with actual
text value..
6. Now suppose I need to show Image data then
I will create one element of that value node.In case of Image
type cell editor source property is given prefrence over alt
property.
set attribute which is bound to alt to blank value
i.e setText("");
and set attribute which is bound to source to some Actual
image name
i.e setImage("Image.gif");
add this to node.
during execution as source property of editor is bound to
Image attribute of node which in turn is set to Actual image file
it will set Image cell editor with that image name and wont look for alt property.
Copy all ur images in src->mimes->components->ur package
Regards
Surender Dahiya -
How To Right Align Images In A Cell?
I am a very amateur (i.e. occasional) web site developer using Dreamweaver CS3 and would be very grateful for any advice on the following.
Several years ago I put together a very simple one page web site using HTML 4.01 transitional and consisting of a single table (width=100%) with several rows. This web site is number one in Google for it's keywords, takes lots of hits every week and because of it's simplicity and the version of HTML used displays well in most web browsers.
The top row of the main table contains a logo which is displayed left-aligned. The web site owner has given in three more images which he would like to go in to the same row but right-aligned. Could anyone point me to info on how to do implement this very simply, preferrably without CSS (although I have a feeling I will probably have to use CSS in the end)....or you could just modify the <td> tag in your stylesheet: td { text-align: right; }
Of course that would affect all the <td> tags throughout your document or your site, depending on where your stylesheet is (embedded in the head of your document or in an external css file). So, mostly contextual selectors are used to specify which <td> tags your want to modify. For example,
#content td { text-align: right; }
will modify only the <td> tags in the content section.
With this method, you do not add any markup to your <td> tags in your html document, so your code remains uncluttered.
Also, the align attribute is still frequently used with the <td> tag. For example, <td align="right">. This attribute is deprecated and will not validate with a strict xhtml doc type. It's not a great sin to use it, but keeping up with standards is a good goal. Again, it adds unnecessary markup to your document. Presentation should be handled with css. -
How to view thumbnail image in Grid before uploading
I am creating a file upload application. I am using a Grid with a filereferencelist object to list all of the uploaded files. I would like to place a thumbnail image of the file in the grid before it is uploaded. I basically used this example from Coding Cowboys (http://weblog.cahlan.com/2006/12/flex-upload-component.html) but I need to add a column for the thumbnail image.
I seen examples of an image getting loaded into a canvas.
http://mariusht.com/blog/2009/04/01/loading-local-images-directly-into-flash-player-10/
http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-p layer-10/
What if I used this as an Item Render field in the grid? -
How do I write data to another cell based on a drop down menu?
Hello. I've been trying to figure this out for a last day or so and my brain is mush since its the first time I've used Numbers.
What I need, is based off this information, is to make summary graphs from information, but the tracky part is, I need to to be catergorized by job site. So if I pull down and select "Job 1" for it to add the required information to a graph for "Job 1" and so on for an average of 8-10 different job sites. The tricky part is, the same job site might show up multiple times and I need it to add only the info from the row that it's on to the graph.
I know this isn't worded very well but any help would be fantastic.m.barr wrote: ...
What I need, is based off this information, is to make summary graphs from information, ...
MB,
I think I have the idea, or at least I can imagine a problem/solution pair that might apply here.
I would begin by starting a new table for your chart. In that new table you would pull in the data that you wish to chart, based on job number, or whatever criteria you have in mind. Use one of the lookup functions to access just the data you need if you want to plot a sequence of values. If you want summary data, use SUMIF and SUMIFS.
Once you have created a table and chart for one job or other criteria, generalize it by substituting a variable in the place where you provide the reference to a particular job. This "variable" would be a reference to a cell where you enter the criteria for that particular instance of the chart.
We can help with the particulars.
Jerry -
Is it possible to auto-populate a row of cells based on a pop-up value...
... that references a value from a column of another table?
EDIT: I note that Jerry has posted much the same solution about the time I was called for dinner (followed by part 2 of the mini series we started watching last night). I'll leave this one up for the tutorial aspects. Other than the use of pop-up menus in Table B, they're essentially the same.
Also, I see I highlighted the wrong ground beef row on the Ingredient table. The correct (93%) one is the one transferred to the second table. Oops!
Barry
dlconnolly wrote:
Good Point, should have done that in the first place. Also, thank you very much for giving this a shot to help me out. Below are my tables that I am trying to link (they did not post as tables so I hope that doesn't further confuse the situation).
Goal: In Table B/Recipes, I would like a drop-down/pop-up option in the 'Ingredient/Column A' column. Based on the choice of ingredient, I would like the Fat/Carbs/Protein row of cells for that ingredient to auto-populate with the data drawn from Table A/Ingredients.
I used the LOOKUP function: =LOOKUP(A2,Ingredients :: Asparagus:'Turkey Breast ', {Ingredients :: B2:D23}). The error message I get is: "B2:D3}" isn't a valid reference.
Hi dl,
Looks like the problem is in the formula above. (repeated with comments below)
<PRE>
Table A: "Ingredients"
Ingredient Fat Carbs Protein
Asparagus 0 5 3
Blueberries F 0 10 1
Blueberries R 0 21 1
Broccoli 0 6 2
Chicken Bre 9 13 35
Chickpeas 3 27 6
Cous Cous 0 36 6
Eggs 10 2 12
Grapes 0 16 1
Green Beans 0 10 2
Ground Beef 90% 9 0 21
Ground Beef 93% 6 0 25
Mozz nonfat 0 4 32
Mozz par tsk 16 3 24
Olive Oil 14 0 0
Pork, ground 18 0 22
Quinoa 4 20 4
Sour Cream 2 1 0
Spinach 1 5 4
Turkey Breast 0 4 20
Table B: (end product)
Ingredient Fat Carbs Protein
Grnd Bf 93% 6 0 25
Broccoli 0 6 2
Quinoa 4 20 4
</PRE>
Posting a screen shot is easier than getting a table to align itself properly here, as the forum software must be forced into recognizing tabs as tabs. Screen shots must be hosted elsewhere (eg. Photobucket, Picasa, Flickr), then the HTML link supplied by the hosting site (on some sites in a "Share this" menu) can be entered into your post to call the image. Be sure to check the Preview tab here (before posting) to see what your post will look like.
Here's your LOOKUP formula. I've replaced the square brackets, parsed by the forum to indicate a link, with curly brackets so they would be visible.
=LOOKUP(A2,Ingredients :: Asparagus:'Turkey Breast ', {Ingredients :: B2:D23}).
The error message I get is: "B2:D3}" isn't a valid reference
"B2:D23}" perhaps?
LOOKUP is discussed on p 217 of the iWork Formulas and Functions User Guide.
It's syntax is:
LOOKUP(search-for, search-where, result-values)
So your formula,in English reads:
Search for: the contents of cell A2 (on this table)
In: the Table "Ingredients" in the columns "Asparagus" to "Turkey Breast"
and return the results in the same row in the columns from B to D in the rows 2 to 23}
I get an (expected) "invalid reference" message for Asparagus:'Turkey Breast '
(Possibly due to my leaving 'use headers as column and row references' unchecked)
Replacing that with the range in which the ingredients are listed (A2:A21), the error message changes to the one you quote.
Even ignoring the square brackets, D23 is an invalid reference on my table, which ends with "turkey breast" in row 21. But even with the specified range completely on the table, the Invalid reference message remains, indicating the square bracket is a problem.
My assumption is that it's there because you are attempting to define the results range as an array including all three columns from which you wish to gather results. Won't work.
From p 217 of the iWork F&F User Guide:
Usage Notes
Both search-where and result-values are normally included and *are specified as either*
*multiple columns or multiple rows, but not both* (one dimensional). However, for
compatibility with other spreadsheet applications, search-where can be specified as
both multiple columns and multiple rows (two dimensional) and result-values can
be omitted.
Editing to limit the result value array to a single column, and removing the square brackets gives a working formula for cell B2 on Table B:
=LOOKUP(A2,Ingredients :: A2:A21, Ingredients :: B2:B21)
Three further edits to the formula are needed before filling down and right to the rest of the active cells in Table B.
The first is to make the column, but not the row, absolute in the cell address for search value so that this reference changes as the formula is filled down, but not as it is filled right.
The second is to make both the columns and rows of the cell addresses specifying the search range absolute so that this range does not change as the formula is filled down, then right.
The third is to make the rows (only) absolute in the result range so that they do not change as the formula is filled down, but do change as it is filled right, ensuring that we retrieve the values from the correct column of "Ingredients" to the corresponding column of Table B.
These are done using the menu revealed by clicking the triangle that appears on the cell range reference when the mouse is placed on it in the formula bar. When done, the formula should look like this:
=LOOKUP($A2,Ingredients :: $A$2:$A$21, Ingredients :: B$2:B$21)
Finishing touch:
As is, the formula will return error messages in rows where there is no entry in column A of Table B. To eliminate those, trap the error using IFERROR:
=IFERROR(formula,"")
(replace formula with the formula above, leaving off the = sign)
Regards,
Barry
PS: The iWork Formulas and Functions Guide may be downloaded through the Help menu in Numbers. You'll also find the equally useful Numbers '09 User Guide at the same location. Both are highly recommended.
B
Message was edited by: Barry -
How to get search help for 2nd parameter based on the 1st parameter value
Hi all!
I have 2 parameters (material no, revision level). I have created a search help for revision level. It has an importing parameter :material no. and one exporting parameter : revision level.When I checked it, it's giving the revision values only for the specified.
In my report , I have kept these 2 materials in my selection screen.For revision level , I have added the matchcode object which I have created. When I pressed F4 for revision level, it's giving all the values irrespective of the material no. in the first parameter. How to solve it? Please suggest.Hi,
Try this code filling internal table fields,
DATA: BEGIN OF values,
OID TYPE ZCL_OBJECT-OBJECTID,
ODEC TYPE ZCL_OBJECT-OBJECT_DESC,
END OF values,
W_FIELD(10).
DATA: ZCL_PROJECT-PROJECTID type zcl_project-projectid,
ZCL_OBJECT-OBJECTID(5).
DATA: progname TYPE sy-repid,
dynnum TYPE sy-dynnr,
dynpro_values TYPE TABLE OF dynpread,
field_value LIKE LINE OF dynpro_values,
values_tab LIKE TABLE OF values.
CALL SCREEN 100.
*& Module VALUE_PROJECTID INPUT
text
*MODULE VALUE_PROJECTID INPUT.
CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
EXPORTING
tabname = 'ZCL_PROJECT'
fieldname = 'PROJECTID'
dynpprog = progname
dynpnr = dynnum
dynprofield = 'ZCL_PROJECT-PROJECTID'.
*ENDMODULE. " VALUE_PROJECTID INPUT
*& Module VALUE_OBJECTID INPUT
text
MODULE VALUE_OBJECTID INPUT.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = progname
dynumb = dynnum
translate_to_upper = 'X'
TABLES
dynpfields = dynpro_values.
READ TABLE dynpro_values INDEX 1 INTO field_value.
W_FIELD = FIELD_VALUE-FIELDVALUE.
SELECT OBJECTID
OBJECT_DESC
FROM ZCL_OBJECT
INTO (VALUES-OID,
VALUES-ODEC)
WHERE PROJECTID = FIELD_VALUE-FIELDVALUE.
APPEND VALUES TO VALUES_TAB.
ENDSELECT.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'OID'
dynpprog = progname
dynpnr = dynnum
dynprofield = 'ZCL_OBJECT-OBJECTID'
value_org = 'S'
TABLES
value_tab = values_tab.
ENDMODULE. " VALUE_OBJECTID INPUT
*& Module INIT OUTPUT
text
MODULE INIT OUTPUT.
progname = sy-repid.
dynnum = sy-dynnr.
CLEAR: field_value, dynpro_values.
field_value-fieldname = 'ZCL_PROJECT-PROJECTID'.
APPEND field_value TO dynpro_values.
IF SY-UCOMM = 'BACK'.
LEAVE program.
ENDIF.
IF SY-UCOMM = 'ANS'.
LEAVE TO SCREEN '0'.
ENDIF.
ENDMODULE. " INIT OUTPUT
START-OF-SELECTION.
WRITE: / field_value-fieldvalue,
W_FIELD.
LOOP AT VALUES_TAB INTO VALUES.
WRITE / VALUES.
ENDLOOP.
if sy-subrc <> 0.
WRITE / field_value-fieldvalue.
endif.
Plzz reward points if it helps -
How to display an image in a window ?
Hi all,
Could someone point me to a document that explains (preferably with code samples) how I go about displaying a JPEG image in a window.
What I'm eventually trying to create is a slideshow, but for now, I just want to add an image to a JFrame and have that display, and even this simple first step is beyond me. There seem to be quite a few different classes to deal with images, but I'm just looking for the simplest one.
With a view to my future requirements, I will want to be able to dynamically shrink an image so that it fits in the window, as well as cropping images so that the full resolution is displayed, but anything that doesn't fit in the window is chopped off.hi,
how to place an image in the cells of a grid and to drag and drop that image. i have the code to locate the postion of each cell on mouse click. now i want to place an image in particular cell and i want to drag and drop that particular image to other cells of grid.
is it possible.
pls give me a suggestion.
here my code:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class Grid
public Grid()
GridPanel gridPanel = new GridPanel();
CellSelector cellSelector = new CellSelector(gridPanel);
gridPanel.addMouseListener(cellSelector);
JFrame f = new JFrame();
//ImageIcon ii= create ImageIcon("C:/Documents and Settings/sreehari.m/Desktop/new/java //pgm/new");
//cellSelector.addImageIcon();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(gridPanel);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
public static void main(String[] args)
new Grid();
class GridPanel extends JPanel
double xInc, yInc;
final int
GRID_SIZE = 4,
DRAW = 0,
FILL = 1,
PAD = 20;
int[][] cells;
public GridPanel()
initCells();
protected void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
double w = getWidth();
double h = getHeight();
xInc = (w - 2*PAD)/GRID_SIZE;
yInc = (h - 2*PAD)/GRID_SIZE;
// row lines
double x1 = PAD, y1 = PAD, x2 = w - PAD, y2 = h - PAD;
for(int j = 0; j <= GRID_SIZE; j++)
g2.draw(new Line2D.Double(x1, y1, x2, y1));
y1 += yInc;
// col lines
y1 = PAD;
for(int j = 0; j <= GRID_SIZE; j++)
g2.draw(new Line2D.Double(x1, y1, x1, y2));
x1 += xInc;
// fill cells
g2.setPaint(Color.red);
for(int row = 0; row < cells.length; row++)
for(int col = 0; col < cells[0].length; col++)
if(cells[row][col] == FILL)
x1 = PAD + col * xInc + 1;
y1 = PAD + row * yInc + 1;
g2.drawString("("+row+","+col+")" , (int) x1+50, (int)y1+50);
//g2.drawString("("+Grid("+row+","+col+")+")" , (int) x1+50, (int)y1+50);
// g2.drawString("("")" , (int) x1+50, (int)y1+50);
// g2.fill(new Rectangle2D.Double(x1, y1, xInc - 1, yInc - 1));
public void toggleCellColor(int row, int col)
int mode = DRAW;
if(cells[row][col] == DRAW)
mode = FILL;
cells[row][col] = mode;
repaint();
private void initCells()
cells = new int[GRID_SIZE][GRID_SIZE];
for(int row = 0; row < cells.length; row++)
for(int col = 0; col < cells[0].length; col++)
cells[row][col] = DRAW;
class CellSelector extends MouseAdapter
GridPanel gridPanel;
public CellSelector(GridPanel gp)
gridPanel = gp;
public void mousePressed(MouseEvent e)
Point p = e.getPoint();
int col = 0, row = 0;
double x = gridPanel.PAD + gridPanel.xInc;
// find column
for(int j = 0; j < gridPanel.GRID_SIZE; j++)
if(p.x < x)
col = j;
break;
x += gridPanel.xInc;
// find row
double y = gridPanel.PAD + gridPanel.yInc;
for(int j = 0; j < gridPanel.GRID_SIZE; j++)
if(p.y < y)
row = j;
break;
y += gridPanel.yInc;
gridPanel.toggleCellColor(row, col);
} -
Button in alv grid cell using REUSE_ALV_GRID_DISPLAY
Hi all,
I want to make the contents of 2 columns of my alv grid as push button with values as text on it. I am not using classes or methods but alv grid fm. On clicking the button one dialog box has to pop up which gives edit option for the values in that coloumn, my question is how to introduce button in alv grid cell? if i can use t_fieldcatalog-icon, then please give me the complete steps for that.
Thanks.this may helps u
u need to copy stadard screen elemetn to MARATAB1(at PF -STATUS)
You should copy the 'STANDARD' GUI status from program <b>SAPLSLVC_FULLSCREEN</b>
type this one in SE41 program name is:<b>SAPLSLVC_FULLSCREEN</b>
status : <b>STANDARD_FULLSCREEN</b>
and copy it ...
Type-pool
type-pools slis.
Tables
tables: mara,sscrfields.
Selection screen
select-options: s_matnr for mara-matnr.
PARAMETERS: p_email TYPE somlreci1-receiver.
TYPES: BEGIN OF t_charmara,
matnr(18) TYPE c, " Material Number
ernam(12) TYPE c, " Person Credited
aenam(12) TYPE c, " Person Changed Object
pstat(15) TYPE c, " Maintenance Status
END OF t_charmara.
Data Declarations
data: rt_extab type slis_t_extab, " Table of inactive function
codes
wa_charmara TYPE t_charmara, " work area of mara Table
fs_fieldcat type slis_t_fieldcat_alv,
" Field catalog with field
descriptions
t_fieldcat like line of fs_fieldcat,
" Table of Field catalog
r_ucomm like sy-ucomm, " User Command
rs_selfield TYPE slis_selfield. " cursor position ALV
data: filedlayout type slis_layout_alv,
heading type slis_t_listheader with header line,
t_event type slis_t_event.
data: fs_event like line of t_event.
data: fs_sort type slis_sortinfo_alv,
t_sort type slis_t_sortinfo_alv.
data: w_char(200) type c,
w_matnr type mara-matnr.
fs_sort-fieldname = 'MATNR'.
fs_sort-up = 'X'.
fs_sort-group = '*'.
append fs_sort to t_sort.
clear fS_sort.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
Internal Tables
data: begin of it_mara occurs 0,
matnr like mara-matnr, " Material Number
ernam like mara-ernam, " Person Credited
aenam like mara-aenam, " Person Changed Object
pstat like mara-pstat, " Maintenance Status
end of it_mara.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
*at selection-screen on field event
AT SELECTION-SCREEN on s_matnr.
PERFORM f0100_VALIDATE_MATERIAL_NUMBER.
start-of-selection.
retrive Data from the data base table Mara
perform retrive_data_from_mara.
end-of-selection.
*Field catalog with field descriptions
perform fieldcat.
*perform top_of_page.
PERFORM EVENT_LIST.
*ALV Grid Display
perform alv_display.
Creating one Push button ENTER
perform maratab1 USING RT_EXTAB.
*& Form f0100_VALIDATE_MATERIAL_NUMBER
text
There are no interface parameters to be passed to this subroutine
FORM F0100_VALIDATE_MATERIAL_NUMBER .
select matnr " Material Number
from mara
up to 1 rows
into mara-matnr
where matnr in s_matnr.
endselect.
IF sy-subrc NE 0.
clear sscrfields-ucomm.
MESSAGE e000 WITH 'Enter valid Material number'(003).
ENDIF. " IF sy-subrc NE 0
ENDFORM. " f0100_VALIDATE_MATERIAL_NUMBER
*& Form retrive_data_from_mara
text
*There are no interface parameters to be passed to this subroutine
FORM retrive_data_from_mara .
select matnr " Material Number
ernam " Person Credited
aenam " Person Changed Object
pstat " Maintenance Status
from mara
into table It_mara
where matnr in s_matnr.
IF sy-subrc NE 0.
MESSAGE i001 WITH 'Records are not found'.
exit.
stop.
ENDIF. " IF sy-subrc NE 0
ENDFORM. " retrive_data_from_mara
*& Form fieldcat
text
*There are no interface parameters to be passed to this subroutine
FORM fieldcat .
*field catalog for MATNR
t_FIELDCAT-REF_TABNAME = 'MARA'.
t_fieldcat-fieldname = 'MATNR'.
t_fieldcat-col_pos = 1.
append t_fieldcat to fs_fieldcat.
clear t_fieldcat.
*field catalog for ERNAM
t_FIELDCAT-REF_TABNAME = 'MARA'.
t_fieldcat-fieldname = 'ERNAM'.
t_fieldcat-col_pos = 2.
append t_fieldcat to fs_fieldcat.
clear t_fieldcat.
*field catalog for AENAM
t_FIELDCAT-REF_TABNAME = 'MARA'.
t_fieldcat-fieldname = 'AENAM'.
t_fieldcat-col_pos = 3.
append t_fieldcat to fs_fieldcat.
clear t_fieldcat.
*field catalog for PSTAT
t_FIELDCAT-REF_TABNAME = 'MARA'.
t_fieldcat-fieldname = 'PSTAT'.
t_fieldcat-col_pos = 4.
append t_fieldcat to fs_fieldcat.
clear t_fieldcat.
ENDFORM. " fieldcat
*& Form EVENT_LIST
text
*There are no interface parameters to be passed to this subroutine
FORM EVENT_LIST .
fs_event-name ='TOP_OF_PAGE'.
fs_event-form = 'TOP_PAGE'.
append fs_event TO t_EVENT.
CLEAR FS_EVENT.
fs_event-name ='END_OF_PAGE'.
fs_event-form = 'END_PAGE'.
append fs_event TO t_EVENT.
CLEAR FS_EVENT.
fs_event-name ='END_OF_LIST'.
fs_event-form = 'LIST_END'.
append fs_event TO t_EVENT.
CLEAR FS_EVENT.
ENDFORM. " EVENT_LIST
*& Form alv_display
text
*There are no interface parameters to be passed to this subroutine
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'MARATAB1'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_STRUCTURE_NAME =
IS_LAYOUT =
IT_FIELDCAT = FS_FIELDCAT
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT = T_SORT
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS = T_EVENT
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IR_SALV_LIST_ADAPTER =
IT_EXCEPT_QINFO =
I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_MARA[]
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. " alv_display
form TOP_PAGE.
data:tbl_listheader type slis_t_listheader,
wa_listheader type slis_listheader .
wa_listheader-typ = 'S'.
wa_listheader-info = 'Created by : Vijay Pawar'.
append wa_listheader to tbl_listheader.
wa_listheader-typ = 'S'.
concatenate ' Date ' sy-datum into
wa_listheader-info separated by space.
append wa_listheader to tbl_listheader.
wa_listheader-typ = 'S'.
concatenate ' From ' s_matnr-low ' To ' s_matnr-high into
wa_listheader-info separated by space.
append wa_listheader to tbl_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = tbl_listheader
I_LOGO =
I_END_OF_LIST_GRID =
I_ALV_FORM =
endform. " form TOP_PAGE.
form END_PAGE.
STATICS W_PAGE TYPE I .
data:tbl_listheader type slis_t_listheader,
wa_listheader type slis_listheader .
wa_listheader-typ = 'S'.
wa_listheader-info = W_PAGE.
append wa_listheader to tbl_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = tbl_listheader
I_LOGO =
I_END_OF_LIST_GRID =
I_ALV_FORM =
add 1 to w_page.
endform. " form END_PAGE.
form list_end.
data:tbl_listheader type slis_t_listheader,
wa_listheader type slis_listheader .
wa_listheader-typ = 'S'.
wa_listheader-info = '......................................Last Page'
append wa_listheader to tbl_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = tbl_listheader
I_LOGO =
I_END_OF_LIST_GRID =
I_ALV_FORM =
endform. " form list_end.
*& Form maratab1
text
-->P_RT_EXTAB text
FORM maratab1 USING P_RT_EXTAB.
SET PF-STATUS 'MARATAB1' EXCLUDING rt_extab.
ENDFORM. " maratab1
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
case r_ucomm.
when 'ENTER'.
perform bulid_xls_data_table.
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email "'[email protected]'
'Example .xls documnet attachment'
'XLS'
'filename'
changing gd_error
gd_reciever.
perform populate_email_message_body.
PERFORM initiate_mail_execute_program.
endcase. " case r_ucomm.
endform. " FORM user_command
perform populate_email_message_body.
PERFORM initiate_mail_execute_program.
CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'
EXPORTING
DATA_FILENAME = 'MARA.XLS'
DATA_PATH_FLAG = 'W'
DATA_ENVIRONMENT =
DATA_TABLE = ITAB[]
MACRO_FILENAME =
MACRO_PATH_FLAG = 'E'
MACRO_ENVIRONMENT =
WAIT = 'X'
DELETE_FILE = 'X'
EXCEPTIONS
NO_BATCH = 1
EXCEL_NOT_INSTALLED = 2
INTERNAL_ERROR = 3
CANCELLED = 4
DOWNLOAD_ERROR = 5
NO_AUTHORITY = 6
FILE_NOT_DELETED = 7
OTHERS = 8
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
leave to list-processing.
endcase.
*& Form bulid_xls_data_table
text
*There are no interface parameters to be passed to this subroutine
FORM bulid_xls_data_table .
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
CONCATENATE 'matnr' 'ernam' 'aenam' 'pstat'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT It_mara INTO wa_charmara.
CONCATENATE wa_charmara-matnr wa_charmara-ernam
wa_charmara-aenam wa_charmara-pstat
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP. " LOOP AT it_mara INTO...
ENDFORM. " bulid_xls_data_table
*& Form send_file_as_email_attachment
Send email
-->P_IT_MESSAGE text
-->P_IT_ATTACH text
-->P_P_EMAIL text
-->P_0387 text
-->P_0388 text
-->P_0389 text
-->P_0390 text
-->P_0391 text
-->P_0392 text
<--P_GD_ERROR text
<--P_GD_RECIEVER text
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM. " send_file_as_email_attachment
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
Instructs mail send program for SAPCONNECT to send email.
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
form populate_email_message_body.
REFRESH it_message.
it_message = 'Please find attached a list test mara records'.
APPEND it_message.
endform. "form populate_email_message_bod
rewards if it helps u -
Embedding images in excel cells-please provide code examples
I need to create excel worksheet and embed an image in a cell. After looking at the POI javadoc and examples, I cannot figure out how to embed the image in a cell, only in the sheet. Does POI support this? I have also been looking a using Jexcel and would like to know if Jexcel supports this? If anyone has answers, please provide code examples.
thanksI need to create excel worksheet and embed an image in a cell. After looking at the POI javadoc and examples, I cannot figure out how to embed the image in a cell, only in the sheet. Does POI support this? I have also been looking a using Jexcel and would like to know if Jexcel supports this? If anyone has answers, please provide code examples.
thanks -
Hi All,
Based on condition how can i add image to Table cell.Hi,
Its very simple and straightforward.
All you need to do is:
1...Create a context(value attribute) of type string.
2...I am assuming that you have created a table, and mapped its columns with a node.
3...In the <i>TableCellEditor</i> of your desired column, map the above context with the <i>imagesource</i> property.
4...In the code, set the value of this context to the image name(eg: abc.gif), on satisfying of a condition.
5...However, keep in mind to set the context value to some default blank image in the doinit() of the view, else, you will get a null pointer exception.
I hope this solves your problem.
Keep posting if you have any further queries.
Regards,
Hanoz -
Re: How to display an image in a grid cell and drag and drop
hi all,
i have the code to create cells in the rectangular box and it will display the positions of each cell on mouse click.
can we place an image in one cell and drag that image to other cells. can we do this,,
can any one know about this,
reply's are appreciated,
regards,
hariThis was given in reply 3 on this thread.
Maybe you are looking for
-
I'm going to be as descriptive as possible, in a hope to actually pinpoint an issue. Not too long ago, my "Lock" function starting acting wonky. It'd lock itself while "Unlocked", and vise versa. This happened for a few days, while all other function
-
Cable equivalent of Universal Dock ?
Hi, What I'm looking for seems quite simple but I can't find it anywhere. I understand the Universal Dock (latest version) is the only one that supports video out using the official Apple RCA cable (which I already have). BUT, I also want to make use
-
Flash Media 2 OS Compatibility
Is there a Flash Media for 64-bit OS's, such as Windows 2003 64? Is the 32-bit version of Flash Media Server able to load on Windows 2003 64 without issues? Are there plans for a 64-bit version of Flash Media Server?
-
Who ever configure address book with Outlook connector successfully?
I have problem about this configuration (Personal address and Outlook connector) for a while so please tell me if anyone can do it successfully.
-
Stuck on "Signing in..." Windows 8
Ok, so ive done some searching before posting, and all things ive seen suggested aren't working. The windows 8 skype app works, and so does the app on my phone, the desktop client refuses to sign in though. Here is what i've tried. Installed all win