Last string font

Someone have any idea how change font last string in a report?

I'm not sure - I have used "span" before to colour code a row based on status for example but not the last row. What is the business reason for this? Do you mean the last row in the dataset or the last row per paginated report page?
Phil

Similar Messages

  • User defined function for getting last string in the line

    Hi Experts,
    I am not java expert, can anyone give me user defined function for getting last string in the line.
    for example if the source field is "NEW ARBOUR SQUARE"  i want to pass to target field only last string that is "SQUARE"
    please help me out of this.
    Kind Regards.
    Praveen.

    You don't even need a UDF for this. In the graphical editor look for the standard functions and once you do a scroll over on 'text functions; you will find what you are looking for.
    Just a piece of advice, try keeping UDF's to minimum unless really required or it is complicated without it.
    regards

  • How to find the last string value in dynamic object?

    Hi All,
    I am trying to find the last string value in dyanamic objects,Any one have solution for this.
    Ex:
    my data :12347-ebjdone-525-ecgfjf-25236-defdafgdeg
    And i want to show the output is :defdafgdeg
    Any ideas:
    Thanks
    Srini

    For oracle try using oracle function.
    e.g.
    SELECT  reverse(substr(reverse('12347-ebjdone-525-ecgfjf-25236-defdafgdeg'),1,instr(reverse('12347-ebjdone-525-ecgfjf-25236-defdafgdeg'),'-','1'))) from dual
    Object definition might look like:
    reverse(substr(reverse({ObjectName}),1,instr(reverse({ObjectsName}),'-','1')))
    Regards,
    Kuldeep
    Edited by: Kuldeep Chitrakar on Feb 12, 2010 8:12 AM

  • Recommendations on using fonts on a string

    I am building a chat application and I know that I want to make it so that the user can change the formatting of his message on the fly (bold, italic, sizing, etc.). I need to pass this information between the client and the server. I was wondering if there were any java classes that would help me accomplish this (aside from String and Font obviously). I guess what I'm looking for is some sort of formatted string class that allows you to store a string with associated font information. I don't have a problem building this myself, I just don't want to unnecessarily reinvent the wheel.
    One idea is to take the formatted string from the GUI and convert it to plain text (something along the lines of BB code that you see on many forums), pass that information as just a string, then convert it back to formatted text on the receiver's GUI.
    Another idea is to have a special class that holds a list of string-font pairs that would allow for the string to be formatted in such a way that the user doesn't have to have his entire string formatted the same (msn messenger-style) but could have different parts of the string formatted in different fonts. I could pass that object to the server to be distributed to the other client and relatively minimal code would need to be written. The down side of this is that it would increase the network traffic on the system, which I'm not too keen on.
    Any ideas/recommendations will be greatly appreciated.

    Darryl.Burke wrote:
    It beats un/wrapping everyones text in HTML.Hmm.. a JEditorPane constructed with type as "text/html" returns the underlying html from a call to getText () and displays formatted text by calling setText with the html Strng as a argument.
    dbok, but if this is an IM program does that mean people have to enter their text as html?
    if i type "how are *you* friend" into the IM box and hit send, he'll have to convert it to html:
    "<html>how are <br>you</br> friend</html>".
    the "DefaultStyledDocument" is already Serializable.

  • How can I display special characters of NonEuropean languages (French, Italian, Spanish, German and Portuguese.) using import string mechanism

    I would like to translate the User Interface of my application to French, Italian, Spanish, German and Portuguese.
    When I put special characters in the import string file they showed up as ? (question mark)
    The import strings file includes the following parameters for each string: font, text, size and style. (but no field for script)
    In order to use a unicode font such as Arial I need to select a french script. But this option is not supported bu LabView (As far as I saw)
    A) Is there a font which is directly German/ French etc and not regula font + script parameter?
    B) Are there another required step
    s for special characters support? (When I put speciual characters in the import string file the showed up as ? question mark)

    This was discussed last week in this group- read the previous messages.
    Look for the thread "Foreign Languages in Labview"
    And recite the mantra
    ActiveX is good
    ActiveX is holy
    All Hail Bill
    Those who claim otherwise are heretics and not to be trusted
    Actually, in this case the non-ActiveX suggestions may be good.
    talia wrote in message
    news:[email protected]..
    > How can I display special characters of NonEuropean languages (French,
    > Italian, Spanish, German and Portuguese.) using import string
    > mechanism

  • Embedded Fonts a Combo Box and complete madness

    I have a combo box that has an array of fonts loaded into
    them, not here is my problem. For some reason, when i select the
    fonts in the array, some of them change and some of them dont. I
    have created font symbols like instructed in the live docs, but i
    dont get why they arent showing up..
    i.e. I have 7 fonts loaded into this combo box and i can
    select Arial Bold and my text field will show the text in arial
    bold, but when i select hobo, i get some substitute!
    here's my code, maybe you guys will see something i
    haven't.. the fonts in particular i am having trouble with: Bookman
    Old Style, BrushScript and Hobo.

    there are many points/issues here. here are some:
    1. Your array called fonts contains eight strings such as
    'new Arial()', whereas i think what you were trying to achieve here
    is to create references to the fonts in the library. to do this
    remove the quotation marks.
    2. To be able to create references to the fonts in the
    library, ensure that the font symbols in the library contain class
    names, with base classes of flash.text.Font. do this by selecting
    'Linkage' on your library fonts.
    3. Ensure that your text field is set to embed fonts - either
    in authoring, or with actionscript
    eg.outputTB1.embedFonts=true;
    4. you set up fonts_array with eight font names and then in
    your for loop, you again add eight fonts to this array. this is
    redundant.
    5. in the for loop you have the line: fonts_array.push(new
    String(fonts[ i]));
    this appears to be an attempt at converting a reference to a
    font into a font name. this isn't going to work. if you had set up
    references to fonts to begin with (see point 1), and this line
    wasn't redundant (see point 4), you would extract the font name
    like so: fonts_array.push(fonts[ i].fontName)
    6. maintaining two arrays of fonts is unecessary. i would
    recommend just maintain your fonts array with references to fonts,
    and extract font names from these references. this would look
    something like the code attached below.
    7. One last thing - i notice that you have at least two of
    your fonts - arial and arial bold, probably have different
    formatting. if some are bold and some are not, you will need to
    specify the bold property also. eg. font.bold=true

  • How to change font/ font color etc in a graphic object using JCombobox?

    Hello
    My program im writing recently is a small tiny application which can change fonts, font sizes, font colors and background color of the graphics object containing some strings. Im planning to use Jcomboboxes for all those 4 ideas in implementing those functions. Somehow it doesnt work! Any help would be grateful.
    So currently what ive done so far is that: Im using two classes to implement the whole program. One class is the main class which contains the GUI with its components (Jcomboboxes etc..) and the other class is a class extending JPanel which does all the drawing. Therefore it contains a graphics object in that class which draws the string. However what i want it to do is using jcombobox which should contain alit of all fonts available/ font sizes/ colors etc. When i scroll through the lists and click the one item i want - the graphics object properties (font sizes/ color etc) should change as a result.
    What ive gt so far is implemented the jcomboboxes in place. Problem is i cant get the font to change once selecting an item form it.
    Another problem is that to set the color of font - i need to use it with a graphics object in the paintcomponent method. In this case i dnt want to create several diff paint.. method with different property settings (font/ size/ color)
    Below is my code; perhaps you'll understand more looking at code.
    public class main...
    Color[] Colors = {Color.BLUE, Color.RED, Color.GREEN};
            ColorList = new JComboBox(Colors);
    ColorList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                     JComboBox cb = (JComboBox)ev.getSource();
                    Color colorType = (Color)cb.getSelectedItem();
                    drawingBoard.setBackground(colorType);
              });;1) providing the GUI is correctly implemented with components
    2) Combobox stores the colors in an array
    3) ActionListener should do following job: (but cant get it right - that is where my problem is)
    - once selected the item (color/ font size etc... as i would have similar methods for each) i want, it should pass the item into the drawingboard class (JPanel) and then this class should do the job.
    public class DrawingBoard extends JPanel {
           private String message;
           public DrawingBoard() {
                  setBackground(Color.white);
                  Font font = new Font("Serif", Font.PLAIN, fontSize);
                  setFont(font);
                  message = "";
           public void setMessage(String m) {
                message = m;
                repaint();
           public void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  //setBackground(Color.RED);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint             
                  g2.drawString(message, 50, 50);
           public void settingFont(String font) {
                //not sure how to implement this?                          //Jcombobox should pass an item to this
                                   //it should match against all known fonts in system then set that font to the graphics
          private void settingFontSize(Graphics g, int f) {
                         //same probelm with above..              
          public void setBackgroundColor(Color c) {
               setBackground(c);
               repaint(); // still not sure if this done corretly.
          public void setFontColor(Color c) {
                    //not sure how to do this part aswell.
                   //i know a method " g.setColor(c)" exist but i need to use a graphics object - and to do that i need to pass it in (then it will cause some confusion in the main class (previous code)
           My problems have been highlighted in the comments of code above.
    Any help will be much appreciated thanks!!!

    It is the completely correct code
    I hope that's what you need
    Just put DrawingBoard into JFrame and run
    Good luck!
    public class DrawingBoard extends JPanel implements ActionListener{
         private String message = "message";
         private Font font = new Font("Serif", Font.PLAIN, 10);
         private Color color = Color.RED;
         private Color bg = Color.WHITE;
         private int size = 10;
         public DrawingBoard(){
              JComboBox cbFont = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
              cbFont.setActionCommand("font");
              JComboBox cbSize = new JComboBox(new Integer[]{new Integer(14), new Integer(13)});
              cbSize.setActionCommand("size");
              JComboBox cbColor = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbColor.setActionCommand("color");
              JComboBox cbBG = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbBG.setActionCommand("bg");
              add(cbFont);
              cbFont.addActionListener(this);
              add(cbSize);
              cbSize.addActionListener(this);
              add(cbColor);
              cbColor.addActionListener(this);
              add(cbBG);
              cbBG.addActionListener(this);
         public void setMessage(String m){
              message = m;
              repaint();
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(bg);//set background color
              g2.fillRect(0,0, getWidth(), getHeight());          
              g2.setColor(color);//set text color
              FontRenderContext frc = g2.getFontRenderContext();
              TextLayout tl = new TextLayout(message,font,frc);//set font and message
              AffineTransform at = new AffineTransform();
              at.setToTranslation(getWidth()/2-tl.getBounds().getWidth()/2,
                        getWidth()/2 + tl.getBounds().getHeight()/2);//set text at center of panel
              g2.fill(tl.getOutline(at));
         public void actionPerformed(ActionEvent e){
              JComboBox cb = (JComboBox)e.getSource();
              if (e.getActionCommand().equals("font")){
                   font = new Font(cb.getSelectedItem().toString(), Font.PLAIN, size);
              }else if (e.getActionCommand().equals("size")){
                   size = ((Integer)cb.getSelectedItem()).intValue();
              }else if (e.getActionCommand().equals("color")){
                   color = (Color)cb.getSelectedItem();
              }else if (e.getActionCommand().equals("bg")){
                   bg = (Color)cb.getSelectedItem();
              repaint();
    }

  • Problem with conversion of strings like THISStr - this_str capitalization

    Problem with conversion of strings like. THISStr -> this_str
    Can anybody pass on the reverse code. I have one, but its faulty.
    public static String convertFromPolycaps(String str) {
              Pattern pattern = Pattern.compile("\\p{Upper}+");
              Matcher matcher = pattern.matcher(str);
              StringBuffer result = new StringBuffer();
              // We do manual replacement so we can change case
              boolean notFirst = false;
              int grpP = 0, grpA = 0;
              String last = "";
              String now = "";
              while (matcher.find()) {
                   grpA = matcher.end();
                   if (notFirst) {
                        now = matcher.group().substring(0).toLowerCase();
                        if (grpA - grpP > 1) {
                             matcher.appendReplacement(result, now);
                             result =
                                  new StringBuffer(
                                       result.substring(0, (result.length() - 1))
                                            + "_"
                                            + result.substring(result.length() - 1));
                        } else {
                             matcher.appendReplacement(result, "_" + now);
                   } else {
                        matcher.appendReplacement(result, matcher.group().substring(0).toLowerCase());
                        notFirst = true;
                   grpP = matcher.end();
                   ////index++;
                   last = now;
              matcher.appendTail(result);
              System.err.println(str + " : " + result.toString());
              return result.toString();
         }succesfully converts :
    AccountNmnc : account_nmnc
    CustNameJ : cust_name_j
    Resume : resume
    BeneBrCode : bene_br_code
    ApprovedPerson : approved_person
    but fails for:
    GLCode : glcode
    VISHALErrCode : vishalerr_code
    GHASUNNAcNo : ghasunnac_no

    Can anybody pass on the reverse code. I have one, but
    its faulty.Post it, I'm sure we can fix it...

  • Font Book is showing fonts in non-english characters

    Been installing my old fonts and the like to Font Book on Mountain Lion but I seem to be running into a small issue as I install.
    Besides the fact that I'm getting the 'A-image' for some of the fonts, a fair few of the fonts themselves also seem to be showing up in what looks to be some sort of alternate language? 
    I uploaded a few examples here as well to help explain the problem I'm running into.
    This is actually a fairly new computer, only a few days old, so there's hasn't been a lot that I've done that I could assume would be doing this.
    Any help or suggestions would be great, thank you in advance for any assistance you can provide!

    The first and third fonts are showing their Hebrew characters as a sample, the second one is showing its Thai characters.  The 4th one is showing a character from the Apple Last Resort Font, which indicates a problem accessing the proper character.
    I don't know why Fontbook does this, but I haven't seen any reports so far that it affects the usability of the fonts in question in any way.   Does it for you?

  • Memory Leak with new Font()

    Hello all,
    Not sure if this is the right place to post this but here goes. I have a program that needs to change the font of at least 250,000 letters, however after doing this the program runs slow and laggy as if changing the fonts of each letter took up memory and never released it? Here is a compilable example, Click the button at the bottom of the window and watch the letter it is currently working on. You will notice that around 200,000 it will begin to not smoothly count up anymore but count in kind of a skipping pattern. This seems to get worse the more you do it and seems to indicate to me that something is using memory and not releasing it. I'm not sure why replacing a letter's font with a new font would cause more memory to be taken up I would think if I was doing it properly it would simply replace the old font with the new one not taking anymore memory then it did before. Here is the example: This program sometimes locks up so be prepared. If someone could maybe point out what is causing this to take up more memory after changing the fonts that would be great and hopefully find a solution :) Thanks in advance.
    -neptune692
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package paintsurface;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.util.List;
    public class PaintSurface implements Runnable, ActionListener {
    public static void main(String[] args) {
            SwingUtilities.invokeLater(new PaintSurface());
    List<StringState> states = new ArrayList<StringState>();
    Tableaux tableaux;
    Random random = new Random();
    Font font = new Font("Arial",Font.PLAIN,15);
    //        Point mouselocation = new Point(0,0);
    static final int WIDTH = 1000;
    static final int HEIGHT = 1000;
    JFrame frame = new JFrame();
    JButton add;
    public void run() {
            tableaux = new Tableaux();
            for (int i=250000; --i>=0;)
                    addRandom();
            frame.add(tableaux, BorderLayout.CENTER);
            add = new JButton("Change Font of letters - memory leak?");
            add.addActionListener(this);
            frame.add(add, BorderLayout.SOUTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(WIDTH, HEIGHT);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    public void actionPerformed(ActionEvent e) {
        new Thread(new ChangeFonts()).start();
    void addRandom() {
            tableaux.add(
                            Character.toString((char)('a'+random.nextInt(26))),
                            UIManager.getFont("Button.font"),
                            random.nextInt(WIDTH), random.nextInt(HEIGHT));
    //THIS CLASS SEEMS TO HAVE SOME KIND OF MEMORY LEAK I'M NOT SURE?
    class ChangeFonts implements Runnable {
        public void run() {
        Random rand = new Random();
            for(int i = 0; i<states.size(); i++) {
                font = new Font("Arial",Font.PLAIN,rand.nextInt(50));
                states.get(i).font = font;
                add.setText("Working on letter - "+i);
    class StringState extends Rectangle {
            StringState(String str, Font font, int x, int y, int w, int h) {
                    super(x, y, w, h);
                    string = str;
                    this.font = font;
            String string;
            Font font;
    class Tableaux extends JComponent {
            Tableaux() {
                    this.enableEvents(MouseEvent.MOUSE_MOTION_EVENT_MASK);
                    lagState = createState("Lag", new Font("Arial",Font.BOLD,20), 0, 0);
            protected void processMouseMotionEvent(MouseEvent e) {
                    repaint(lagState);
                    lagState.setLocation(e.getX(), e.getY());
                    repaint(lagState);
                    super.processMouseMotionEvent(e);
            StringState lagState;
            StringState createState(String str, Font font, int x, int y) {
                FontMetrics metrics = getFontMetrics(font);
                int w = metrics.stringWidth(str);
                int h = metrics.getHeight();
                return new StringState(str, font, x, y-metrics.getAscent(), w, h);
            public void add(String str, Font font, int x, int y) {
                    StringState state = createState(str, font, x, y);
                    states.add(state);
                    repaint(state);
            protected void paintComponent(Graphics g) {
                    Rectangle clip = g.getClipBounds();
                    FontMetrics metrics = g.getFontMetrics();
                    for (StringState state : states) {
                            if (state.intersects(clip)) {
                                    if (!state.font.equals(g.getFont())) {
                                            g.setFont(state.font);
                                            metrics = g.getFontMetrics();
                                    g.drawString(state.string, state.x, state.y+metrics.getAscent());
                    if (lagState.intersects(clip)) {
                    g.setColor(Color.red);
                    if (!lagState.font.equals(g.getFont())) {
                        g.setFont(lagState.font);
                        metrics = g.getFontMetrics();
                    g.drawString("Lag", lagState.x, lagState.y+metrics.getAscent());
    }Here is the block of code that I think is causing the problem:
    //THIS CLASS SEEMS TO HAVE SOME KIND OF MEMORY LEAK I'M NOT SURE?
    class ChangeFonts implements Runnable {
        public void run() {
        Random rand = new Random();
            for(int i = 0; i<states.size(); i++) {
                font = new Font("Arial",Font.PLAIN,rand.nextInt(50));
                states.get(i).font = font; // this line seems to cause the problem?
                add.setText("Working on letter - "+i);
    }

    neptune692 wrote:
    jverd wrote:
    You're creating a quarter million distinct Font objects, and obviously you must be hanging on to all of them because each character is having its font set to the newly created object. So if you have 250k chars, you're forcing it to have 250k Font objects.
    Since the only difference is that rand.nextInt(50) parameter, just pre-create 50 Font objects with 0..49, stick 'em in the corresponding elements in an array, and use rand.nextInt to select the Font object to use.That does make sense but it does that when the the program is first launched and doesn't lag. But the second and third time you change the letters font it seems to lag so if it wasn't taking up more memory the second time it should perform like it did when it first launched. I don't care to investigate any further. The real problem is almost certainly the quarter million Font objects. It could be that 250k is fine, but by the time you get to 500k, it has to do a lot of GC, and that's where the slow down is coming. You might even be able to make it work better with the code you have just by tweaking the GC parameters at startup, but I wouldn't bother. Fix the code first, and then see if you have issues.
    Does creating a new font for each of those letters not replace the old font object? If it didn't use more memory the second and third time I don't think you would see the skipping in the counter and the slowing down of the iterations. So it must be remembering some of the old font objects or am I wrong?Using new always creates a new object. When you do it the second time around, and call letter.setFont(newFont), the old Font object is eligible for GC. That doesn't mean it will be GCed right away though. The JVM can leave them all laying around until it runs out of memory, and then GC some or all of them.

  • Need a way to extract substring from string in oracle

    Hi all,
    I have one requirement related to extracting string from a paramater.
    suppose the string may like this in various format
    string:= 'This my string <Rid//problem/123456>'
    or
    string:= '<Rid//problem/123456> This my string'
    or
    string:= ' This is <Rid//problem/123456> my string'
    Now my requirement is i need to extract 123456 using pl/sql block.
    is there any way in oracle to get this thing done.
    Thanks n regards
    Laxman

    Hi,
    What version of Oracle ?
    How do you delimit the string to extract ?
    - always between the last / and before the >
    - the last string mande of number ?
    - the first string made of number ?
    Here are 3 possible answers :SQL> with s as (
      2  select 'This my string <Rid//problem/123456>' s from dual
      3  union all select '<Rid//problem/123456> This my string' from dual
      4  union all select ' This is <Rid//problem/123456> my string' from dual
      5  )
      6  select s.s,
      7  regexp_replace(s,'^.*/([0-9]*).*$','\1') r1,
      8  regexp_replace(s,'^[^0-9]*(.*?)[^0-9]*$','\1') r2,
      9  regexp_replace(s,'^.*/(.*?)>.*$','\1') r3
    10  from s ;
    S                                        R1       R2       R3
    This my string <Rid//problem/123456>     123456   123456   123456
    <Rid//problem/123456> This my string     123456   123456   123456
    This is <Rid//problem/123456> my string 123456   123456   123456If you're on 10g or more...
    Of course it also works in PL/SQL :SQL> l
      1  declare
      2  r1 varchar2(50) := 'This my string <Rid//problem/123456>';
      3  r2 varchar2(50) := '<Rid//problem/123456> This my string';
      4  r3 varchar2(50) := ' This is <Rid//problem/123456> my string';
      5  r1b varchar2(50);
      6  r2b varchar2(50);
      7  r3b varchar2(50);
      8  begin
      9  r1b := regexp_replace(r1,'^.*/([0-9]*).*$','\1') ;
    10  r2b := regexp_replace(r2,'^[^0-9]*(.*?)[^0-9]*$','\1') ;
    11  r3b := regexp_replace(r3,'^.*/(.*?)>.*$','\1') ;
    12  dbms_output.put_line('1 : '||r1||' -> '||r1b);
    13  dbms_output.put_line('2 : '||r2||' -> '||r2b);
    14  dbms_output.put_line('3 : '||r3||' -> '||r3b);
    15* end;
    SQL> /
    1 : This my string <Rid//problem/123456> -> 123456
    2 : <Rid//problem/123456> This my string -> 123456
    3 :  This is <Rid//problem/123456> my string -> 123456
    PL/SQL procedure successfully completed.Edited by: Nicosa on Jul 23, 2010 3:22 PM

  • Sending Strings Over GKSession - How to stop some craziness?

    Sounds simple, right? But the tricky part is I am trying to retain the header structure from GKTank... I am quite desperate for help at this point as I've been flailing around on this all day and all night....
    All my other events use this structure already and work just fine..and after a ton of trial and error I'm very close... hoping I can get one of you experts to take a look. The issue is that when my strings are less than 8 characters, the results get very strange....
    Here's the relevant code: (kMaxPacketSize is a constant of 1024)
    To send Data: (this is straight from GKTank, actually)
    - (void)sendNetworkPacket:(GKSession *)session packetID:(int)packetID withData:(void *)data ofLength:(int)length reliable:(BOOL)howtosend {
    static unsigned char networkPacket[kMaxPacketSize];
    const unsigned int packetHeaderSize = 2 * sizeof(int); // we have two "ints" for our header
    if(length < (kMaxPacketSize - packetHeaderSize)) { // our networkPacket buffer size minus the size of the header info
    int *pIntData = (int *)&networkPacket[0];
    // header info
    pIntData[0] = packetNumber++;
    pIntData[1] = packetID;
    // copy data in after the header
    memcpy( &networkPacket[packetHeaderSize], data, length );
    NSData *packet = [NSData dataWithBytes: networkPacket length: (length+8)];
    if(howtosend == YES) {
    [session sendDataToAllPeers:packet withDataMode:GKSendDataReliable error:nil];
    } else {
    [session sendDataToAllPeers:packet withDataMode:GKSendDataUnreliable error:nil];
    In this particular case, I began by calling the above method thusly:
    NSString *myText = self.myLabel.text
    NSInteger len = [myText length];
    [self sendNetworkPacket:mySession packetID:NETWORKTEXTEVENT withData:myText ofLength:(len*2)+1 reliable:YES];
    and unwrapping like this on the other end:
    NSString *pStringData = (NSString *)&incomingPacket[8];
    Works like a charm... strings show up just fine on the other device.... except when the string is less than 8 characters...this causes crashes of EXCBADACCESS on the receiving device. When I check values for these short strings prior to sending over GKSession, the memcpy command does not properly embed the string into 'networkPacket' and keeps remnants from the last string that was transmitted.
    So, in an attempt to work around what is probably a flaw in my logic, I decided to see what happens if I pad the beginning and end of these short strings to make them over 8 characters, by defining another string 'spacer' and then sending a padded string instead of myText:
    NSString *spacer = @"zZzZ";
    NSString *bufText = [spacer stringByAppendingString:[myText stringByAppendingString:spacer]];
    len = [bufText length];
    [self sendNetworkPacket:mySession packetID:NETWORKTEXTEVENT withData:bufText ofLength:(len*2)+1 reliable:YES];
    This got rid of the issues with memcpy, and now all strings are embedded in 'networkPacket' properly, some just have the spacers on the beginning and end... no problem, right? I figured I'd just filter out the spacers on the other end, but guess what? I have even tried using the same code to disassemble the packet, prior to sending it, exactly the way I do on the receiving device... it disassembles fine, and I can re-create the string from the raw packet I send....
    However... (and this ONLY happens on the strings that have been padded) when I receive the data through GKSession I get totally random characters and even lengths! Sometimes I get odd system strings like 'tpenable' or 'uni0164' ... it's so bizarre... I don't understand what is making the padded strings get treated differently.... I tried padding all strings just to check and then they all act like this when transmitted... and again when I use the following code, prior to sending the packet, both test1 and test2 look fine:
    NSString *test1 = (NSString *)&networkPacket[8];
    unsigned char *testPacket = (unsigned char *)[packet bytes];
    NSString *test2 = (NSString *)&testPacket[8];
    NSLog (@"netPacket");
    NSLog (test1);
    NSLog (@"Packet");
    NSLog (test2);
    If you have any ideas, I'd really appreciate it!
    Message was edited by: Tech Guru

    [dataString bytes] returns a +const void*+ type. The compiler is complaining because you passed that +const void*+ pointer to a method that declared the 3rd arg to be a void*. The difference between the two pointers is that the first type doesn't want you to change the bytes that it's pointing to, while the second type doesn't care.
    For example:
    - myMethod:(const char *)foo {
    foo[3] = 'A'; // changing the value of the 4th byte at address foo
    In the above, the compiler should warn that your method changed the data which was referenced by a const char* type.
    But sendNetworkPacket doesn't do anything naughty like the above, it just copies the data at the given addy into a buffer. So you could have declared the data param as const void* like this:
    - (void)sendNetworkPacket:(GKSession *)session packetID:(int)packetID withData:(const void *)data ofLength:(int)length reliable:(BOOL)howtosend;
    The above change should get rid of the warning. If the compiler thinks you're changing that data in sendNetworkPacket (we know you're not doing that, but it's hard to argue with a compiler), you'll then get a new warning to that effect. In that case you might as well put a type cast in the call. I.e. take 'const' back out of the method declaration, and cast the arg in the call like this:
    [self sendNetworkPacket:mySession packetID:NETWORKTEXTEVENT withData:(void*)[dataString bytes] ofLength:len reliable:YES];
    The first try is preferable, since we like to avoid type casts, and since (I assume) sendNetworkPacket really doesn't want to change that data. But if the compiler won't cooperate, the second way will always work for you.
    Btw, putting the text into a NSData object is fine by me, but you could've also used any number of NSString methods that aren't deprecated (e.g. [myText UTF8String]). No need to go there now though. I'm guessing your early problems with some perfectly good methods were due to data type glitches. Because of mismatched data types, you may have abandoned the correct approach and gone down the wrong path.
    Once things got to the point where a NSString pointer was sent to memcpy, I think all of us were at risk of falling into darkness. I stared at the code for a very long time, wondering if everyone in the World but me knew that trick. Next time you get a data type error, maybe post the code here and let us try and help out while the problem is still easy to solve, ok?
    All the best,
    Ray

  • How to measure the size of a string

    windows app store how to measure the size of a string?
    string str = "Hello word windows app store";

    if you need the actual width the string occupies in pixels than use (see
    this MSDN link for more details):
    Graphics.MeasureString(String, Font)
    if you only need the "length" of the string i.e. no. of characters than use (see
    this MSDN link for more details):
    str.Length
    dont forget to bing / google :)
    hope this helps!
    Graphics.MeasureString(String, Font) can not use in windows store app.
    TextBlock has Measure()
    method, as following:
    Size MeasureString(string content, Size availableSize, double fontSize, string fontFamily="Segoe UI")
        TextBlock tb = new TextBlock();
        tb.TextWrapping = TextWrapping.Wrap;
        tb.Text = content;
        tb.FontFamily = new Windows.UI.Xaml.Media.FontFamily(fontFamily);
        tb.FontSize = fontSize;
        tb.Measure(availableSize);
        return tb.DesiredSize;
    Test:
    string str = "Hello word windows app store";
    Size size = MeasureString(str, new Size(800, 600), 40);

  • Pdf do not display correctly / missing fonts?

    Some of my recently downloaded pdfs don't seem to display parts of them correctly in Preview (or in Acrobat Reader). Could this be due to missing fonts. I get a message in Acrobat: "Cannot find or create "last resort" font...
    How do I get this font? Should I have it?
    Thanks for your help,

    If Disk Utility shows no Permissions or Disk problems, then it could be a corrupted Preferences file, Preview could be corrupted, or maybe you need to do some system maintenance.
    But you left it on all night, so daily maintenance would have been done around 3:00 am, so that shouldn't be the problem. You might try locating the com.apple.preview.plist file in Preferences and Trash it (but don't empty the Trash) and then try opening the file with Preview again and see what happens. If the problem is still there, then I would try putting Preview in the Trash (again, don't empty the Trash) and use your original install discs and Pacifist to reinstall just Preview and try it again. You can get Pacifist here:
    http://www.charlessoft.com/
    Hope this helps,
    Mulder

  • Problem in using Font class

    In this code i try to make font preview on the word "Test" by selecting font name , style and size
    but when i select font name and style the word " Test" disappear
    why ??
    please say to me the correct way to do this .
    my code :
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GraphicsEnvironment;
    import java.awt.GridLayout;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.border.TitledBorder;
    class FontClass extends JDialog {
        Box mainComBoxPanel = Box.createHorizontalBox();
        JPanel comfontpanel, comfontstaylePanel, comsizeFontpanel, mainSamplePanel, samplePanel, mainPanel, applayPanel, mainApplayPanel;
        JLabel labelFont, labelFontstyle, labelSize, sampleLabel;
        TitledBorder titleSample, fontProperties;
        JComboBox comboBoxFont, comboBoxFontstyle, comboBoxFontSize;
        JButton applayButton, canelButton;
        String[] font;
        int[] fontStyle = {Font.BOLD, Font.ITALIC, Font.BOLD | Font.ITALIC};
        String[] fontNames = {"Bold", "Italic", "BoldItalic"};
        String[] sizeFont = {"20", "22", "24", "26", " 28", "36", "48", "72"};
        public FontClass() {
            font = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
            comboBoxFont = new JComboBox(font);
            IntializePanel();
            IntializeLapel();
            //applay panel contain ok & applay buttons
            applayPanel.setLayout(new GridLayout(2, 1));
            applayButton = new JButton("applay");
            canelButton = new JButton("cancel");
            applayPanel.add(applayButton);
            applayPanel.add(canelButton);
            mainApplayPanel.setBackground(Color.BLUE);
            mainApplayPanel.add(applayPanel);
            // panels for comboBox
            comfontpanel.setLayout(new GridLayout(2, 1));
            comfontstaylePanel.setLayout(new GridLayout(2, 1));
            comsizeFontpanel.setLayout(new GridLayout(2, 1));
            // sampel panel for previewing font properties
            titleSample = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3), "sample");
            samplePanel.setBorder(titleSample);
            sampleLabel.setText("Test");
            samplePanel.setBackground(Color.BLUE);
            samplePanel.add(sampleLabel);
            comboBoxFontstyle = new JComboBox();
            for (int i = 0; i < fontStyle.length; ++i) {
                comboBoxFontstyle.addItem(fontNames);
    comboBoxFontSize = new JComboBox();
    for (int i = 0; i < sizeFont.length; ++i) {
    comboBoxFontSize.addItem(sizeFont[i]);
    comfontpanel.add(labelFont);
    comfontpanel.add(comboBoxFont);
    comfontstaylePanel.add(labelFontstyle);
    comfontstaylePanel.add(comboBoxFontstyle);
    comsizeFontpanel.add(labelSize);
    comsizeFontpanel.add(comboBoxFontSize);
    comfontpanel.setPreferredSize(new Dimension(40, 40));
    comfontstaylePanel.setPreferredSize(new Dimension(40, 40));
    comsizeFontpanel.setPreferredSize(new Dimension(40, 40));
    fontProperties = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 5), "Font properties");
    mainComBoxPanel.setBorder(fontProperties);
    mainComBoxPanel.add(comfontpanel);
    mainComBoxPanel.add(Box.createHorizontalStrut(10));
    mainComBoxPanel.add(comfontstaylePanel);
    mainComBoxPanel.add(Box.createHorizontalStrut(10));
    mainComBoxPanel.add(comsizeFontpanel);
    mainComBoxPanel.add(Box.createHorizontalGlue());
    samplePanel.setPreferredSize(new Dimension(200, 100));
    mainSamplePanel.add(samplePanel);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(mainComBoxPanel, BorderLayout.NORTH);
    mainPanel.add(mainSamplePanel, BorderLayout.SOUTH);
    mainPanel.add(mainApplayPanel, BorderLayout.EAST);
    getContentPane().add(mainPanel);
    comboBoxFont.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    String newFontName = (String) comboBoxFont.getSelectedItem();
    sampleLabel.setFont(new Font(newFontName, WIDTH, WIDTH));
    comboBoxFontstyle.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    int newFontStyle = fontStyle[comboBoxFontstyle.getSelectedIndex()];
    sampleLabel.setFont(new Font(null, newFontStyle, WIDTH));
    comboBoxFontSize.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    int newFontSize = Integer.parseInt((String) comboBoxFontSize.getSelectedItem());
    sampleLabel.setFont(new Font(null, WIDTH, newFontSize));
    private void IntializePanel() {
    mainPanel = new JPanel();
    comfontpanel = new JPanel();
    comfontstaylePanel = new JPanel();
    comsizeFontpanel = new JPanel();
    mainSamplePanel = new JPanel();
    samplePanel = new JPanel();
    mainApplayPanel = new JPanel();
    applayPanel = new JPanel();
    private void IntializeLapel() {
    labelFont = new JLabel("Font:");
    labelFontstyle = new JLabel("Font Style:");
    labelSize = new JLabel("Size:");
    sampleLabel = new JLabel("Test");
    public static void main(String[] args) {
    FontClass fontClass = new FontClass();
    fontClass.setSize(new Dimension(500, 400));
    fontClass.setLocationRelativeTo(null);
    fontClass.setVisible(true);
    fontClass.setResizable(false);

    Add a single item listener to all your combo boxes:
            ItemListener itemListener=new ItemListener() {
                public void itemStateChanged(ItemEvent e) {
                    String selectedFontName = (String) comboBoxFont.getSelectedItem();
                    int selectedfontStyle = fontStyle[comboBoxFontstyle.getSelectedIndex()];
                    int selectedfontSize = Integer.parseInt((String) comboBoxFontSize.getSelectedItem());
                    sampleLabel.setFont(new Font(selectedFontName, selectedfontStyle, selectedfontSize));
            comboBoxFont.addItemListener(itemListener);
            comboBoxFontstyle.addItemListener(itemListener);
            comboBoxFontSize.addItemListener(itemListener);By the way, have tried searching for 'Swing Font Chooser' on Google?
    Thanks!

Maybe you are looking for

  • Formatted hard drive and changed computer, how can I sync with iTunes?

    Yes, I formatted my hard drive and got a new computer, without thinking that it would cause any problems. Now I have installed iTunes and want to sync my iPhone, but it wants to erase my current music files. What do I do? P.s. If there are any ppl wh

  • What is the use of service entry sheet in plant maintenance module.

    Hi Expert, I want know about, What is the use of service entry sheet in plant maintenance? Regards, Ram Rathode

  • Has anyone had issues with Firefox 13.1 while scrolling web pages

    While scrolling most but not all internet page words get jumpy and blurred. This same thing happened on version 13. I had no problems with 12 or ones before it.

  • Questions about creating sets using FM

    Hi, It seems that FM G_SET_CREATION is not a true function module where I could provide all the parameters wit the values and the sets would be created automatically. Somehow, I have to write a program to do the BDC steps. Has anyone written a progra

  • Time to Restart

    Does the number of mounted volumes (hard drives and partitions) have any impact on the time it takes for the Mac Pro to go from the Restart command to black screen and chime (all apps already closed, btw)? Seems like it has gotten much longer with th