How to create a labelfield with fixed width and dynamic height?

I got this question in fact for a long time and I have not found answer in this forum so far.

As we know, we can use:

public int getPreferredWidth()
{
    return fixedSize;
}

protected void layout(int width,int height)
{
    super.layout(getPreferredWidth(), getPreferredHeight());
    super.setExtent(getPreferredWidth(), getPreferredHeight());
}

to set the width fixed in a field, but if the text is too long and should be multiline, this will bring problem, getPreferredHeight() only returns the preferred height, which is actually not the actual height, so the text will be hashed.

So what should this setting? height?

super.setExtent(getPreferredWidth(), height));

No.... the height value is too large.

So, how can we set this parameter to make this labelfield looks perfectly.

Any idea?

A search on the web is expected to increase a lot of examples of functions in Java text wrapping. Especially for BlackBerry, you can use Font.getAdvance (String text, int start, int len) to measure the width of a text segment without the expense of creation of substrings.

The basic logic is to analyze the text character by character. If the "\n" character, force a line break. If the character is a space, then it is a line break candidate; Check if the line so far is set. If so, then move the candidate to that character end and continue; If this is not the case, go back to the previous candidate break and put an end to the line right there. The loop is initialized so that there is always at least one character on the line. The process ends when you run out of text. Details (including dealing with empty text, several spaces, etc.) are kept as an exercise for the reader, or search the Web well.

I wouldn't worry efficiency. Put on the page of the field is not all that often, and when it's done, there's no escape from the need to make the work of packaging line at some point before the text is rendered on the screen. One way to avoid unnecessarily repeating work is to memoize the function of packaging line: wrapped lines and the width of the film cache and reuse them as needed. The cache is marked invalid if changes to text or the current width and the width of the film cached differ.

Tags: BlackBerry Developers

Similar Questions

  • How to create the table with the rows and columns using the layout?

    One of my friends advised me to put my site on the mode of provision as it is better than the standard as he said
    but I couldnot make an ordinary table with the rows and columns in mode available th
    y at - there someone who can tell me how to?
    Thank you very much

    Wednesday, April 18, 2007 21:01:38 + 0000 (UTC), "Mr.Ghost".
    wrote:

    > A friend of mine advised me to put my whole site on the mode of disposal as its
    > better than standard, as he says

    Your friend won't. Don't listen to him any more. Mode of disposal creates
    very fragile and rigid code pauses at the first opportunity.

    Gary

  • How to create a rectangle of fixed ratio and move without cutting the image?

    I know it's a simple question with a simple answer, but I did not yet find that answer. Usually, I crop my photos in a size 2 to 1 fixed ratio for Twitter. I used to extend the fixed ratio to the size I wanted and then move the tool of selection of ants marching to the area I wanted to reframe. However, in the last few months I'm not able to move the selection without cutting the photo. I used to create my selection and move the cursor over the moving dotted line and then move the selection. This is never a problem. All the answers as to what I might hurt?

    Thanks in advance.

    Sandra

    If there is no selection and you move the selection with the "MOVE TOOL" it will reduce the image

    To move the selection without cutting image, use any 'Sélection' tool instead of the move tool.

  • How to create a grid with the tables and Boolean values?

    As part of a larger project, I'm trying to create a Subvi, which will allow me to spend a "cursor" in a 3 x 3 matrix.

    It should be 2 Boolean inputs, one for move them down in the table and the other to move them to the right. Once reached the edge of the table, the "cursor" will start back at the beginning.

    I have a vague idea of a table to 2 dimensions with LED. Once 'down' has been selected, the corresponding light to (0,0), light (0.1). Goes the same for the button 'right '. When 'down' is pressed (0.2), the LED should turn off, and LED (0,0) must light up.

    I'm sure it has something to do with the initialization of the tables, but I can't seem to find the right way to do it.

    Any help is much appreciated. Thank you!

    Your array is always empty.  Look at the detailed help for the function page replace table subset.  He says that the function has no effect if the specified index refers to a location outside the table.

    What you see on the Panel is only a view and has nothing to do with what is in the table.

    Lynn

  • Table with fixed header and the left column

    I created a table in my application with the fixed left column (left most column is fixed and remaining columns are scrolling from left to right). is it possible to create a table with fixed position and fixed left column?

    Suppose there are 50 rows and 10 columns in my paintings, and only 3 columns and 15 rows are visiable on the screen

    (1) when the user scroll left to right left only most of the columns must be fixed. Remaining cap of the table and column scroll left to right and vice versa. also

    (2) when user scroll high high bottems single topic most must be fixed and remaining all lines (with to the left most column) should be scrollable.

    I am able to put in place a point at the top, but not both. Please suggest

    "If I repopulate the value in the cell when user scrolling, shell, I get scrolling effect correctly as it only shows half cell when the user highlight half of the cell."

    Approach using TablelayoutManager display single cells and scrolling would be cell at a time.  And Yes, you will need to override navigationMovement and n of methods appropriate TouchEvent your TableLayoutManager so that he knows when to fill the cells.

    Another alternative is to have four managers, we don't the the upper left corner (the dead angle), one to make the top row (column headings), one to make the left column (row headings), and the other to do the rest (data).  Place all these in a delicate header and line manager.  Only allow the user to scroll the data part.  Have the difficult Manager to listen the scroll events.  Then have the wily Manager add and remove the dummy column and header line managers as appropriate.  Note that these topic fields would not good passes, they would be either there or they would not be displayed. That would give you your 1/2 a scroll of the cell.  And you wouldn't have to substitute anything to detect movement, you would have left the listener do scrolling for you.

  • How to create a window with its own window border other than the local system window border?

    How to create a window with its own window border other than the local system window border?

    For example, a border: a black line with a width of 1, then a transparent line with a width of 5. Inside, it's the content pane.

    In JavaSE, there seems to be for the JFrame paintComponent() method to realize the effect.

    I can't see what you're trying to do now: it's a little trickier. You need stage.initStyle (StageStyle.TRANSPARENT), and I think you have to imitate the transparent part of the border by the presence of a second vessel inside the root container, properly positioned.

    Something like:

    
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    
    public class CustomBorderExample extends Application {
    
      @Override
      public void start(Stage primaryStage) {
      AnchorPane root = new AnchorPane();
      root.setStyle("-fx-border-color: black; -fx-border-width: 1px; ");
    
      StackPane mainContainer = new StackPane();
        AnchorPane.setTopAnchor(mainContainer, 5.0);
        AnchorPane.setLeftAnchor(mainContainer, 5.0);
        AnchorPane.setRightAnchor(mainContainer, 5.0);
        AnchorPane.setBottomAnchor(mainContainer, 5.0);
      mainContainer.setStyle("-fx-background-color: aliceblue;");
      root.getChildren().add(mainContainer);
    
      primaryStage.initStyle(StageStyle.TRANSPARENT);
      final Button closeButton = new Button("Close");
        mainContainer.getChildren().add(closeButton);
        closeButton.setOnAction(new EventHandler() {
          @Override
          public void handle(ActionEvent event) {
            Platform.exit();
          }
        });
      primaryStage.setScene(new Scene(root,  300, 200, Color.TRANSPARENT));
      primaryStage.show();
      }
    
      public static void main(String[] args) {
      launch(args);
      }
    }
    
  • 5.6.1 pages: How to create a table with more than 999 lines?

    5.6.1 pages: How to create a table with more than 999 lines?

    The table on Pages v5.6.1 line selector is limited 3-digit, as it is in Pages ' 09 v4.3. Either use LibreOffice Writer, who does not have any constraint line on processing tables 3-digit, or any application spreadsheet for top 3-digit row needs.

  • How to create Hlp files with labwindows 9.0

    Hello

    I used to create the dll with Labwindows 8.5 and use them with TestStand... The advantage is that with the help file, I can add information to the Fp file and loading the DLL with TestStand, the "?" button to open the help file...

    But the problem is that I can't find help with Labwindows 9.0 generation...

    Does anyone know how to create file hlp with Labwindows 9.0?

    The procedure with Labwindows 8.5 has been:

    Modification of the PS file, then generate the Option-> windows help

    Thank you very much

    Ronan

  • How to create an app with space name?

    Hi all

    How to create an application with the space, for example "Hello Word" name When I run my Simulator, I got ' Hello$ 20World "instead. I use the plugin for eclipse for development. I can see the Application descriptor for my application, and it shows the thin space. I tried to change the Blackberry project properties tab generate file output name, but it doesn't help in any way. Please advise...

    Goto Blackberry project properties

    Click the general tab

    Write in title = "Hello World".

    and you can see your title of the modified project

    I hope that you ask for it only!

  • How to create a form with a submit in CC button animate using Actionscript 3

    How to create a form with a submit in CC button animate using Actionscript 3. The file will first be a SWF but will also have the flexibility to export as HTML5

    I've searched high and low for an example of code for this entry.

    Can someone help me please?

    Thank you

    You can use the same graphic assets of basis for two projects, but the coding will be different for everyone.  You must work on the project of a code at a time.

  • How to create dummy data with 1 TB

    Hi Expert,

    May I know how to create dummy data with 1 TB to test performance. ?

    Respect of

    Liang

    what columns you want to include? Basically, you can generate as many lines as you like to connect by queries - something like:

    create the table big_t

    as

    with

    generator1 like)

    Select rownum id

    of the double

    connect by level<=>

    )

    ,

    generator2 as)

    Select lpad ('* ', 1000,' *') col1

    of the double

    connect by level<=>

    )

    Select g1.id

    g2.col1

    of generator1 g1

    generator2 g2

    ;

    Of course, it is not 1 TB, but you can change the number of levels. Who said: I think you need to find a sensitive table first structure.

  • How to create a button with rollover that appears in a different place than the button when you move?

    Hello

    How to create a button with rollover that appears in a different place than the button when you move by using only the Muse (reversal may be a different shape and color of the button). I managed to do it using Photoshop and the separate layers and import it, but it is not a good solution. All suggestions will be welcome.

    Thank you

    You can try to use the widget of the Composition of the ToolTip. In this way, the trigger area is isolated and a "State of reversal" can be placed anywhere on the screen (compared to the trigger).

    • Remove the two triggers additional default
    • Set to display the targets on working capital
    • Select hide all initially.
  • How to create a DVD with Media Encoder? Thank you!

    How to create a DVD with Media Encoder? Thank you!

    Export to mpeg2-DVD and use a design program like still to create DVD compatible files to burn to DVD.

  • How to create a table with these dimensions?

    Still new in Indesign, but I need to create a table like the one below.

    Screen Shot 2015-03-10 at 2.31.25 AM.png


    Select the text tool, I created a block of text and then insert a table. However, I'm lost as to how to change the top line for the length of the two columns from the bottom.
    I looked at the options of panel paintings, but it only allows me to change the number of lines and columns.

    All advice is appreciated. Thank you.

    You must create a table with two rows and two columns.

    To select the first line and click "merge cells".

  • How to create RAID 5 with 6 disks?

    I'm new to vmware. My machine is currently running ESXi 4.1 but the RAID set up gives me no more disk space I was advice to remake the structure of the disc physically to have all 6 disks in RAID 5 and then reinstall ESXi. I'm doing, but I need a direction how to create RAID 5 with 6 disks. Can someone please help with this?

    Thank you

    SD

    Assuming you are using the integrated Smart Array 6i controller it should without a problem. If you can get into the BIOS of conreollers, you can also boot from Smartstart CD and use the ACU (Array Configuration Utility). The ACU has the advantage that you can split the RAID in several logical drives. I usually create a small logical volume (~ 10GB) for the installation of the hypervisor (ESXi) and another large logical volume to the VMFS data store.

    André

    PS: When you respond by e-mail, please do not understand the original message.

Maybe you are looking for

  • My memory of the iphone is always full

    my iphone keeps showing memory full message. Most of the time I am unable to take pictures or videos. I contacted apple to many times, but they never understood what the problem is. I even got a new iphone but still facing same problems. I did a rese

  • loss of partition when adding a new partition on the hard drive

    Under XP SP3, I have connected a HDD backup (1, 5 to) where there was a single logical partition, split into two units of 500 GB each. They were regularly mounted and functional, with their assigned letter (E and F). I decided to add and create a las

  • Disable the hardware buttons

    I would have a configuration option to disable the hardware buttons. Working in landscape mode I touch them often by accident.

  • MS Streets & Maps works in Windows 7 Home Premium 64-bit.

    It cannot get MS Streets & Maps works on Windows 7 Home Premium 64 bit. See the title.

  • Signed app refuses to launch the device - how to debug?

    I'm trying to get my first (Powernap) app to run on a physical device.  It works well in the Simulator, but it will not start when I try to put on a real device.  I do not yet know where to start, when I press the icon, nothing happens.  Literally no