GridLayout.

Hello

IAM trying to use gridlayout but it seems any class in

NET. RIM. Device.API.UI.Container. *; to gridlayout

is - anyone can provide any other resource to gridlayout.

I also tried the example extracts the developer code samples

Rgds

Nadir

Hello Nadirfirfire and welcome to the forum.

It is usual to ask only a questino in a 'topic', so if you have another unrelated question, it is best to start another Thread.

In addition, it is always a good idea to search the Forum before asking a question.  Your question was asked several times before, so maybe you'll find an answer immediately.

Good luck and I hope you find the forum useful.

Tags: BlackBerry Developers

Similar Questions

  • Change stacklayout to gridlayout in the listview

    How can I change to battery/grid listview layout? Or how a list replacing with lines from the list of tiles? Can anyone help? Thank you!

    Thanks for the inspiration!

    I did this way:

    Page {
        ListView {
            id: listView
            layout: (mainPage.listviewLayout == "stack") ? stackListLayout : gridListLayout
        }
        attachedObjects: [
                GridListLayout {
                    id: gridListLayout
                    headerMode: ListHeaderMode.None
                },
                StackListLayout {
                    id: stackListLayout
                    headerMode: ListHeaderMode.None
                }
            ]
        actions: [
                ActionItem {
                    title: "Change layout"
                    onTriggered: {
                        if (mainPage.listviewLayout == "stack") {
                            mainPage.listviewLayout = "grid";
                            listView.layout = gridListLayout;
                        } else {
                            mainPage.listviewLayout = "stack";
                            listView.layout = stackListLayout;
                        }
    
                    }
                }
            ]
        property string listviewLayout: "stack"
    }
    
  • How to resize any UIComponent that is inside a container with a GridLayout/RowLayout

    Hello

    How resize us a component, let's say, a button.

    I tried to use:

    1 Button.setActualSize(Number,Number);

    2 Button.width =? Button.Height =?

    None seem to work when the button is hosted in a RowLayout.

    Any thoughts?

    See my response to your other recent thread on the resizing of an image.

  • Qml gridlayout rectangle icons

    I'm reproducing the rectangle icons on the homescreen of BB10 in a grid format. Right now I have a two-dimensional image of gird with my icons (no distinguishable area) and would like to see the box while that on top of my background color. How does qml cascading. Thank you

    You can use use ListView with the presentation of the grid.  Then using components customized to list items.  You should be able to define a background color of each element (transparent grey), have an ImageView and etiquette in addition to this.  Finally, have a background (anything of your choice) for the entire Page... this piece would be independent of the ListView.

  • ListView grid change to list dynamically

    Dear developers

    I have a listview that is represented by a grid. But I want a menuaction to change the schedule to the list and vice versa. But it seems more difficult, so I thought. My griditems are different then my listitems. For those who must change too.

    That's what I have so far but I'm stuck to be honest.

    import bb.cascades 1.0
    
    Container {
        property bool isGrid: true
    
        ListView {
            id: listView
            dataModel: channelListVM.otherDataModel
            horizontalAlignment: HorizontalAlignment.Fill
            layoutProperties: StackLayoutProperties {
                spaceQuota: 1.0
            }
            layout: isGrid ? gridLayout : stackLayout
            listItemComponents: [
                ListItemComponent {
                    type: "gridItem"
                    GridItem {
                        contextActions: ActionSet {
                            title: ListItemData.name
                            actions: [
                                ActionItem {
                                    title: qsTr("Favorite")
                                    imageSource: "asset:///img/bb_action_favorites.png"
                                    onTriggered: {
                                        ListItemData.favorite()
                                    }
                                }
                            ]
                        }
                    }
                },
                ListItemComponent {
                    type: "listItem"
                    MyListItem {
                        contextActions: ActionSet {
                            title: ListItemData.name
                            actions: [
                                ActionItem {
                                    title: qsTr("Favorite")
                                    imageSource: "asset:///img/bb_action_favorites.png"
                                    onTriggered: {
                                        ListItemData.favorite()
                                    }
                                }
                            ]
                        }
                    }
                }
            ]
    
            function itemType(data, indexPath) {
                if(isGrid) {
                    return "gridItem";
                }
    
                return "listItem";
            }
    
            attachedObjects: [
                StackListLayout {
                    id: stackLayout
                },
                GridListLayout {
                    id: gridLayout
                    columnCount: 3
                    horizontalCellSpacing: 10.0
                    verticalCellSpacing: 10.0
                    cellAspectRatio: 1
                }
            ]
        }
    }
    

    And when I change the isGrid true or false, it amends the provision but it seems that the UI is not updated. How can I fix without working with 2 ListViews and hide/show them about the property?

    Thanks in advance

    Since you're using the itemType function you do not require a change in your database. However, given that you match the layout of your choice of item type, you will need to notify the ListView that its cache is no longer valid. If ListView will not selection of the type of return until you load a new element in its cache.

    To do this, you just have your DataModel emit a signal after you change your property to isGrid. This is done via DataModel::itemsChanged. Since you want your entire list to rebuild, you want to give him the DataModelChangeType::Init.

    Code wise, you need to add this call:

    channelListVM.otherDataModel.itemsChanged(DataModelChangeType.Init)
    
  • The width of the container, footer.

    Hello, I am a new user of the native SDK, and I write in order to solve several problems that I had to work with containers.

    First of all, I created the following structure:

    import bb.cascades 1.3

    {Page}
    {Of container
    layout: {StackLayout}
    direction: LayoutOrientation.TopToBottom
    }
    background: Color.White
    topPadding: 50.0
    {Of container
    horizontalAlignment: P
    background: Color.White
    bottomMargin: 45.0
    ImageView {}
    ID: logoCht
    imageSource: "asset:///logo_cht.png."
    Accessibility.Name: "logoCht".
    accessibility.labelledBy: [logoCht]
    }
    }
    {Of container
    horizontalAlignment: P
    background: Color.White
    layout: {GridLayout
    columnCount: 3
    }
    ImageButton {}
    ID: btnPaquetes
    defaultImageSource: "asset:///paquetexdpi.png".
    pressedImageSource: "asset:///paquetexdpi.png".
    disabledImageSource: "asset:///paquetexdpi.png".
    accessibility.labelledBy: [btnPaquetes]
    Accessibility.Name: "Boton packages.
    onClicked: {}

    }
    }
    ImageButton {}
    ID: btnHoteles
    defaultImageSource: "asset:///hotelesxdpi.png".
    pressedImageSource: "asset:///hotelesxdpi.png".
    disabledImageSource: "asset:///hotelesxdpi.png".
    accessibility.labelledBy: [btnHoteles]
    Accessibility.Name: "Boton Hoteles.
    onClicked: {}
                    
    }
    }
    ImageButton {}
    ID: btndestinos
    defaultImageSource: "asset:///destinosxdpi.png".
    pressedImageSource: "asset:///destinosxdpi.png".
    disabledImageSource: "asset:///destinosxdpi.png".
    accessibility.labelledBy: [btndestinos]
    Accessibility.Name: "Boton Destinos".
    onClicked: {}
                    
    }
    }
    }
    {Of container
    horizontalAlignment: P
    background: Color.White
    layout: {GridLayout
    columnCount: 3
    }
    ImageButton {}
    ID: btnBuscador
    defaultImageSource: "asset:///buscadorxdpi.png".
    pressedImageSource: "asset:///buscadorxdpi.png".
    disabledImageSource: "asset:///buscadorxdpi.png".
    accessibility.labelledBy: [btnBuscador]
    Accessibility.Name: "Boton Buscador".
    onClicked: {}
                    
    }
    }
    ImageButton {}
    ID: btnVuelos
    defaultImageSource: "asset:///vuelosxdpi.png".
    pressedImageSource: "asset:///vuelosxdpi.png".
    disabledImageSource: "asset:///vuelosxdpi.png".
    accessibility.labelledBy: [btnVuelos]
    Accessibility.Name: "flights of Boton.
    onClicked: {}
                    
    }
    }
    ImageButton {}
    ID: btnContactenos
    defaultImageSource: "asset:///contactenosxdpi.png".
    pressedImageSource: "asset:///contactenosxdpi.png".
    disabledImageSource: "asset:///contactenosxdpi.png".
    accessibility.labelledBy: [btnContactenos]
    Accessibility.Name: "Boton Contactenos.
    onClicked: {}
                    
    }
    }
    }
    {Of container
    horizontalAlignment: P
    background: Color.White
    layout: {GridLayout
    columnCount: 2
    }
    bottomMargin: 30.0
    ImageButton {}
    ID: btnLlamar
    defaultImageSource: "asset:///llamarxdpi.png".
    pressedImageSource: "asset:///llamarxdpi.png".
    disabledImageSource: "asset:///llamarxdpi.png".
    accessibility.labelledBy: [btnLlamar]
    Accessibility.Name: "bird call".
    onClicked: {}
                    
    }
    }
    ImageButton {}
    ID: btnChat
    defaultImageSource: "asset:///chatxdpi.png".
    pressedImageSource: "asset:///chatxdpi.png".
    disabledImageSource: "asset:///chatxdpi.png".
    accessibility.labelledBy: [btnChat]
    Accessibility.Name: "bird cat".
    onClicked: {}
                    
    }
    }
    }
    {Of container
    background: Color.LightGray
    preferredHeight: 150
    preferredWidth: 1280
    horizontalAlignment: HorizontalAlignment.Fill
    layout: {GridLayout
    columnCount: 3
    }
                
    ImageView {}
    ID: logoChtFooter
    imageSource: "asset:///logo_cht_movil.png."
    Accessibility.Name: "logoChtFooter".
    accessibility.labelledBy: [logoChtFooter]
    }
    {Label
    text: qsTr ("asdfasdfsdf")
    }
    ImageView {}
    ID: logoIram
    imageSource: "asset:///iram.png."
    Accessibility.Name: "logoIram".
    accessibility.labelledBy: [logoIram]
    }
    }
    }
    }

    But I can't, is to have the footer at the bottom, because it appears next to the buttons.

    Also, I want to know if all of the containers change according with each electronic device and how the containers to get this new size.

    Hoping that you will help me soon.

    Yours faithfully,

    You must create a second container with spaceQuota and verticalAlignment, in this way:

    import bb.cascades 1.3
    
    Page {
        Container {
            layout: StackLayout {
                orientation: LayoutOrientation.TopToBottom
            }
            background: Color.White
            topPadding: 50.0
            Container {//This is what you need
                layoutProperties: StackLayoutProperties {
                    spaceQuota: 1
                }
                verticalAlignment: VerticalAlignment.Fill
                Container {
                    horizontalAlignment: HorizontalAlignment.Center
                    background: Color.White
                    bottomMargin: 45.0
                    ImageView {
                        id: logoCht
                        imageSource: "asset:///logo_cht.png"
                        accessibility.name: "logoCht"
                        accessibility.labelledBy: [ logoCht ]
                    }
                }
                Container {
                    horizontalAlignment: HorizontalAlignment.Center
                    background: Color.White
                    layout: GridLayout {
                        columnCount: 3
                    }
                    ImageButton {
                        id: btnPaquetes
                        defaultImageSource: "asset:///paquetexdpi.png"
                        pressedImageSource: "asset:///paquetexdpi.png"
                        disabledImageSource: "asset:///paquetexdpi.png"
                        accessibility.labelledBy: [ btnPaquetes ]
                        accessibility.name: "Boton Paquetes"
                        onClicked: {
    
                        }
                    }
                    ImageButton {
                        id: btnHoteles
                        defaultImageSource: "asset:///hotelesxdpi.png"
                        pressedImageSource: "asset:///hotelesxdpi.png"
                        disabledImageSource: "asset:///hotelesxdpi.png"
                        accessibility.labelledBy: [ btnHoteles ]
                        accessibility.name: "Boton Hoteles"
                        onClicked: {
    
                        }
                    }
                    ImageButton {
                        id: btndestinos
                        defaultImageSource: "asset:///destinosxdpi.png"
                        pressedImageSource: "asset:///destinosxdpi.png"
                        disabledImageSource: "asset:///destinosxdpi.png"
                        accessibility.labelledBy: [ btndestinos ]
                        accessibility.name: "Boton Destinos"
                        onClicked: {
    
                        }
                    }
                }
                Container {
                    horizontalAlignment: HorizontalAlignment.Center
                    background: Color.White
                    layout: GridLayout {
                        columnCount: 3
                    }
                    ImageButton {
                        id: btnBuscador
                        defaultImageSource: "asset:///buscadorxdpi.png"
                        pressedImageSource: "asset:///buscadorxdpi.png"
                        disabledImageSource: "asset:///buscadorxdpi.png"
                        accessibility.labelledBy: [ btnBuscador ]
                        accessibility.name: "Boton Buscador"
                        onClicked: {
    
                        }
                    }
                    ImageButton {
                        id: btnVuelos
                        defaultImageSource: "asset:///vuelosxdpi.png"
                        pressedImageSource: "asset:///vuelosxdpi.png"
                        disabledImageSource: "asset:///vuelosxdpi.png"
                        accessibility.labelledBy: [ btnVuelos ]
                        accessibility.name: "Boton Vuelos"
                        onClicked: {
    
                        }
                    }
                    ImageButton {
                        id: btnContactenos
                        defaultImageSource: "asset:///contactenosxdpi.png"
                        pressedImageSource: "asset:///contactenosxdpi.png"
                        disabledImageSource: "asset:///contactenosxdpi.png"
                        accessibility.labelledBy: [ btnContactenos ]
                        accessibility.name: "Boton Contactenos"
                        onClicked: {
    
                        }
                    }
                }
                Container {
                    horizontalAlignment: HorizontalAlignment.Center
                    background: Color.White
                    layout: GridLayout {
                        columnCount: 2
                    }
                    bottomMargin: 30.0
                    ImageButton {
                        id: btnLlamar
                        defaultImageSource: "asset:///llamarxdpi.png"
                        pressedImageSource: "asset:///llamarxdpi.png"
                        disabledImageSource: "asset:///llamarxdpi.png"
                        accessibility.labelledBy: [ btnLlamar ]
                        accessibility.name: "Boton Llamar"
                        onClicked: {
    
                        }
                    }
                    ImageButton {
                        id: btnChat
                        defaultImageSource: "asset:///chatxdpi.png"
                        pressedImageSource: "asset:///chatxdpi.png"
                        disabledImageSource: "asset:///chatxdpi.png"
                        accessibility.labelledBy: [ btnChat ]
                        accessibility.name: "Boton Chat"
                        onClicked: {
    
                        }
                    }
                }
            }
            Container {
                background: Color.LightGray
                preferredHeight: 150
                preferredWidth: 1280
                horizontalAlignment: HorizontalAlignment.Fill
                layout: GridLayout {
                    columnCount: 3
                }
    
                ImageView {
                    id: logoChtFooter
                    imageSource: "asset:///logo_cht_movil.png"
                    accessibility.name: "logoChtFooter"
                    accessibility.labelledBy: [ logoChtFooter ]
                }
                Label {
                    text: qsTr("asdfasdfsdf")
                }
                ImageView {
                    id: logoIram
                    imageSource: "asset:///iram.png"
                    accessibility.name: "logoIram"
                    accessibility.labelledBy: [ logoIram ]
                }
            }
        }
    }
    
  • Image Resizing does not work

    Hi all

    Here is my code. I have a picture on a container with RowLayout, the problem is, I tried to use Image.setActualSize (Number, Number); OR Image.width, Image.height, but it has no effect on the Image.

    The capture of the image follows the size of the original image.

    var foregroundLayout:RowLayout= new RowLayout();
    foregroundLayout.type=RowLayoutType.VERTICAL;foregroundContainer.setActualSize(screenWidth,screenHeight);
    
    //set foregroundLayout as the layout of foregroundContainer
    foregroundContainer.layout=foregroundLayout;[Embed(source="/../assets/images/start_image.png")] //ORIGINAL IMAGE SIZE IS 240x320var startPNG: Class;var startImage:Image=new Image();startImage.setImage(new startPNG());
    startImage.setActualSize(100,100); //THIS LINE DOESNOT HAVE ANY EFFECT
    
    //add startImage to foregroundContainer
    foregroundContainer.addChild(startImage);
    

    I spent the last few hours trying to figure out, but I still can't.

    Any ideas on that? Thank you.

    figured it out

    I changed the GridLayout layout in...

    And I create a GridData for each single control hosted in the breast.

  • two labels in a single line, BUT on the left and right side

    Hello

    I try to have 2 tags aigned in one line, but on both sides of the container. for example,.

    desired output

    # start the container

    -------------------------------------------------

    text1                                               text2

    ...

    -------------------------------------------------

    container #end

    to get two labels in one line, I can use StackLayout and use its orientation (LeftToRight) property. but I get the following result:

    # start the container

    -------------------------------------------------

    text1text2

    ...

    -------------------------------------------------

    container #end

    If I use GridLayout and use HorizontalAlignment.left and HorizontalAlignment.Right on both labels, I get the following result:

    # start the container

    -------------------------------------------------

    Text1

    Text2

    ...

    -------------------------------------------------

    container #end

    Why does not work...

    Page {
        Container {
            layout: DockLayout { }
            Label {
                horizontalAlignment: HorizontalAlignment.Left
                verticalAlignment: VerticalAlignment.Top
                text: "On the left"
            }
            Label {
                horizontalAlignment: HorizontalAlignment.Right
                verticalAlignment: VerticalAlignment.Top
                text: "On the Right"
            }
        }
    }
    
  • How to create a layout three columns of expandable width?

    Hi all

    Using JDeveloper 12.1.3.

    I am trying to create a three-column page layout, two rows, with the column widths of 40%, 10%, 40% and 50% line heights, 50%.  If it's important, the middle column could be a fixed width.  In HTML, it would be something like below:


    <table>
         <tr style="height:50%">
              <td rowspan="2" style="width:40%"></td>
              <td rowspan="2" style="width:10%"></td>
              <td style="width:40%"></td>
         </tr>
         <tr  style="height:50%">
              <td></td>
         </tr>
    </table>  
    

    Any suggestions on how I would go all this in the ADF?  < af:panelSplitter > does not have a % value and < af:gridLayout > is not working correctly or the other.

    I intend to put the tables completely stretched in the 1st and 3rd columns and a group of buttons in the 2nd column.  The end result is looks a bit like a personalized shuttle component.

    Hello

    Why do you use for the design of ADF page html tags?

    for use of three column layout - panelStrtechLayout

    She start, Center, end, high and low side and you can set the width in pixels for each facet according to your requirement

    Here's the value upper and lower facet width 0px use only 3 columns

    Thank you

  • How to get the text to the next line of the Label

    Hello

    I am trying to write a code where when I press Enter the text in the text box appears on the next line of the label. However, each new text is get printed on the same line...

    Here is my code:

    java.applet import. *;

    import java.awt.*. *;

    java.awt.event import. *;

    public class ChatBox extends implements ActionListener Applet

    {

    TextField firstNum, secondNum, resultNum;

    Label label1;

    String str1 = "start chat".

    public ChatBox()

    {

    setLayout (new GridLayout (3, 2, 10, 15));

    setBackground (Color.cyan);

    String message;

    message = "start typing and see the magic."

    setLayout (new GridLayout (2,1,10,120)); 10, 15));

    setBackground (Color.cyan);

    firstNum = new TextField (5);

    firstNum.addActionListener (this);

    Label1 = new Label (firstNum.getText ());

    Add (Label1);

    Add (firstNum);

    }

    public void actionPerformed (ActionEvent e)

    {

    String line = System.getProperty ("line.separator");

    String message = "start typing and see the magic."

    str1 = str1 + newline + firstNum.getText ();

    firstNum.setText("");

    message = message + str1;

    Label1.SetText (str1);

    }

    }

    Is it not possible?
    Guide of nicely with another way to do it.

  • Update 11.1.1.6.0 to 11.1.1.6.4

    Hi all

    Reading the documentation on oracle adf 11.1.1.6.4, I'm interesting in some features in this version of http://docs.oracle.com/cd/E29597_01/web.1111/e28163/af_calendar.htm on the calendar item.

    So, how can I use the 11.1.1.6.4 version? Y at - it a JDEV patch?

    Jhon

    JDEV 11.1.1.6.0

    Well, nothing official. I know that a few new features, such as gridLayout will be available, there is no official list.

    Timo

  • Make a (get) component without pack()

    Hello

    I'm trying to implement Re: JTable column header to span several columns for a covering table header. In this example, scrollPane header is defined AFTER the framework was achieved with pack().
    In my application, however, I have several different tables that I showed a common dialog, which I pass the corresponding array containing only scrollPane. Is there a way to get the scrollPane realized before be displayed? Currently, I met a NullPointerException (to the arrow "->"). I tried doLayout() and validate() nothing helps.
    import java.awt.*;
    import java.util.Collections;
    import java.util.Enumeration;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.TableColumnModelEvent;
    import javax.swing.event.TableColumnModelListener;
    import javax.swing.table.*;
     
    public class MultiSpanHeader1 {
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
    
             @Override
             public void run() {
                new MultiSpanHeader1().makeUI();
             }
          });
       }
     
       public void makeUI() {
          final JFrame frame = new JFrame("MultiSpanHeader test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 200);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
          MyTable myTable= new MyTable();
          JScrollPane scroll= new JScrollPane(myTable);
          JPanel panel = new JPanel(new GridLayout(2, 1));
          panel.add(myTable.dummyHeader);
          panel.add(myTable.getTableHeader());
    // -->
          System.out.println(scroll.getColumnHeader()); // null
          scroll.getColumnHeader().setView(panel); // NPE
          new TableDialog(frame, scroll);
       }
    
    
       class TableDialog extends JDialog {
         public TableDialog(Frame parent, JScrollPane scroll) {
           super(parent, true);
           setLocationRelativeTo(parent);
           add(scroll);
           setVisible(true);
         }
       }
    
    
      class MyTable extends JTable {
        final JTableHeader dummyHeader;
    
        public MyTable() {
          super(5, 6);
          getTableHeader().setReorderingAllowed(false);
          final TableColumnModel model = getColumnModel();
          Enumeration<TableColumn> enumColumns = model.getColumns();
          final List<TableColumn> columns = Collections.list(enumColumns);
          
          final JTable dummy = new JTable(0, 3);
          dummyHeader= dummy.getTableHeader();
          dummyHeader.setReorderingAllowed(false);
          dummyHeader.setResizingAllowed(false);
          final TableColumnModel dummyModel = dummy.getColumnModel();
          Enumeration<TableColumn> enumDummyColumns = dummyModel.getColumns();
          final List<TableColumn> dummyColumns = Collections.list(enumDummyColumns);
          
          model.addColumnModelListener(new TableColumnModelListener() {
             @Override
             public void columnAdded(TableColumnModelEvent e) {
             }
     
             @Override
             public void columnRemoved(TableColumnModelEvent e) {
             }
     
             @Override
             public void columnMoved(TableColumnModelEvent e) {
             }
     
             @Override
             public void columnMarginChanged(ChangeEvent e) {
                dummyColumns.get(0).setWidth(columns.get(0).getWidth());
                dummyColumns.get(1).setWidth(columns.get(1).getWidth() +
                      columns.get(2).getWidth());
                dummyColumns.get(2).setWidth(columns.get(3).getWidth() +
                      columns.get(4).getWidth() + columns.get(5).getWidth());
             }
     
             @Override
             public void columnSelectionChanged(ListSelectionEvent e) {
             }
          });
        }
      }
    
    }

    You will need to substitute JTable #configureEnclosingScrollPane () to do nothing and use get #setColumnHeaderView what auto creates the window:

    import java.awt.EventQueue;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    
    public class TestTable5 {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    JTable table = new JTable(5, 5) {
                        @Override
                        protected void configureEnclosingScrollPane() {
                            // do nothing, custom table header
                        }
                    };
                    JScrollPane pane = new JScrollPane(table);
                    pane.setColumnHeaderView(new JLabel("Hi!"));
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(pane);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    
  • JLabel icons update

    Hello

    I can't update the images defined as icons in a JLabel. I checked the JLabel to change when updateImage() is called - what it does, but the display does not update - the image is just the same as the original that has been loaded image.

    Any help would be appreciated... Thank you.


    ---- some methods and variables omitted ----
    
    public class GraphicInterface extends Reference
    {
        private JFrame frame;
        private Container contentPane;
        private JTextPane imageDisplay;
        private JLabel imageLabel;
    
        public GraphicInterface()
        {
            makeFrame();
        }
    
        private JLabel loadImage(String fileName)
        {
            JLabel label = new JLabel();
            ImageManager image = new ImageManager(fileName);
            label = image.loadImage();
            return label;
        }
        
        private void updateImage(String fileName)
        {
            imageLabel = loadImage(fileName);
        }
    
        private void makeFrame()
        {
            frame = new JFrame("GlossarySearch");
            makeMenuBar();
            
            contentPane = frame.getContentPane();
            contentPane.setLayout(new BorderLayout());
            
            makeSearchBar();
            makeDisplay();
            
            frame.pack();
            frame.setSize(600,400);
            frame.setVisible(true);
            
        }
    
        private void makeDisplay()
        {
            JPanel display = new JPanel();
            display.setLayout(new GridLayout(1,1,5,5));
            contentPane.add(display, BorderLayout.CENTER);
            
            imageLabel = loadImage("default image");
            imageLabel.setBorder(BorderFactory.createTitledBorder("Image"));
            imageLabel.setPreferredSize(new Dimension (200,250));
            display.add(imageLabel);
        }
    }

    When you say "the JLabel changes" I'm guessing that you mean that the JLabel variable named "imageLabel" was the thing that has changed? That won't change the UI for the original JLabel object reference.

    Which is what we need to change. You have a reference to this object in the form of the variable "imageLabel"; to modify the object you call one of its methods, like maybe setIcon() or something... What did your ImageManager class to create the label in the first place.

  • Why the box to uncheck?

    I have a program that has a GUI control that I designed. It consists of several checkboxes within a group of experts, the user can check one or more of them. There are different methods to get all the selections, uncheck the boxes in the code etc. In one place in my software, I need a dialog box should appear when the user checks a box. So I had my control to raise a property-changed event whenever one of the boxes is checked or unchecked. I then catch cela in another part of the code and cause a dialog that ask the user for other options.

    My problem is this: for some strange reason, when the dialog box appears, it is originally be deselected again immediately after it is checked the box. I have prepared a simplified version of the problem code, below. If you comment out the call to ticking(), it works fine (but the dialog box does not appear clearly). Someone at - it ideas, please?
    import java.awt.GridLayout;
    import java.awt.event.*;
    import java.beans.*;
    import java.util.HashSet;
    import javax.swing.*;
    
    public class Testing {
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                @Override public void run() {                  
                    Testing testing = new Testing();
                }
            });
        } 
        
        public Testing() {
            JFrame fmMain = new JFrame();
            CheckBoxes cb = new CheckBoxes("one", "two", "three");
            cb.addPropertyChangeListener(new PropertyChangeListener() {     
                @Override public void propertyChange(PropertyChangeEvent pce) {
                    String category = (String) pce.getPropertyName();
                    if(category.equals("ticking")) {             
                        ticking();  //commenting this out means the boxes are ticked ok
                    }
                }
            });
            fmMain.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            fmMain.add(cb);
            fmMain.pack();
            fmMain.setVisible(true);
        }
        
        private void ticking() {
            final JDialog dlg = new JDialog();
            JButton okbutton = new JButton("OK");
            okbutton.addActionListener(new ActionListener() {
                @Override public void actionPerformed(ActionEvent ae) {
                    dlg.dispose();
                }
            });
            dlg.add(okbutton);
            dlg.setModal(true);
            dlg.pack();
            dlg.setVisible(true);  
        }
        
        class CheckBoxes extends JScrollPane {
            public CheckBoxes(Object... arr) {
                super();
                GridLayout gl = new GridLayout();
                gl.setColumns(1);
            
                JPanel panel = new JPanel();
                setViewportView(panel);
                gl.setRows(arr.length);
                panel.setLayout(gl);
            
                ItemListener cl = new ItemListener() {
                    @Override public void itemStateChanged(ItemEvent ie) {
                        JCheckBox cbi = (JCheckBox) ie.getSource();
                        String propertyName = cbi.isSelected() ? "ticking" : "unticking";      
                        System.out.println("Item event: "+propertyName);
                        CheckBoxes.this.firePropertyChange(propertyName, null, cbi.getText());
                    }
                };
            
                HashSet data = new HashSet();
                for(Object o: arr) {
                    if(!data.contains(o)) {
                        JCheckBox candidate = new JCheckBox(o.toString());
                        panel.add(candidate);
                        candidate.addItemListener(cl);
                        data.add(o);
                    }
                }
            }     
        }
    }

    Cannot see exactly what the problem is, but I would say it is better to let the box change to complete before putting the dialog box. Rather than call the dialog box directly, try EventQueue.invokeLater () to place the call to the dialog box on the queue, to be run when the action box is complete.

  • JComboBox with two columns

    Hello

    I found a nice piece of code in the forum, which extends a JComboBox to display
    two columns.
    Now I am trying to add my own demands, namely the combo should be editable
    and only the first column should appear in the edit field and become the
    selected value.

    I thought to write an own editor that "catches" the posting process for
    manipulate the text that will be displayed. Because the rendering engine uses a
    JPanel to display columns, I expect this Panel must be passed in the
    setItem method (...) the editor. But it isn't, and I can't even detect
    what object is passed.

    I wonder if this approach is advisable at all. If comments or ideas
    are welcome.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class Main extends JFrame {        
        public static final long serialVersionUID= 70L;
    
        public Main() {        
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            final JComboBox<Object> priceList = new JComboBox<>(new Object[] {
                new Object[] { "Lemon", 0.5 },
                new Object[] { "Cherry", 3 },
                new Object[] { "Apple", 1 },
            });
            priceList.setEditable(true);
         priceList.setEditor(new MyEditor());
            priceList.setRenderer(new MyRenderer());
            add(priceList, BorderLayout.CENTER);
    
         JButton b= new JButton("OK");
         b.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             System.out.println(priceList.getSelectedItem());
           }
         });
            add(b, BorderLayout.SOUTH);
            pack();
        }
        
        public static void main(String... args) 
        throws Exception {                
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new Main().setVisible(true);
                }
            });
        }
    
    
    
      class MyEditor extends JTextField implements ComboBoxEditor {
        public static final long serialVersionUID= 71L;
    
        public Component getEditorComponent() {
          return this;
        }
    
        public Object getItem() {
          return getText();
        }
    
        public void setItem(Object obj) {
          System.out.println("Setting item");
          System.out.println(obj);
          if (obj instanceof JPanel) System.out.println("Panel");
          if (obj instanceof JLabel) System.out.println("Label");
          if (obj instanceof String) System.out.println("String");
          setText("Hello");
        }
      }
    
     
    /** 
     * This class uses panel with two labels to render the list (combobox) cell.
     */
      class MyRenderer extends JPanel implements ListCellRenderer<Object> {
        public static final long serialVersionUID= 72L;
        JLabel labels[] = { new JLabel(), new JLabel() };
    
        public MyRenderer() {
            setLayout(new GridBagLayout());
            // Add labels
            GridBagConstraints c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 0.1;
            add(labels[0],c);
            add(labels[1]);
        }
    
        public Component getListCellRendererComponent(JList<?> list, Object value,
                   int index, boolean isSelected, boolean cellHasFocus) {
            Object rowData[] = (Object[])value;
            // Prepare colors
            Color foreground = isSelected? 
                list.getSelectionForeground(): list.getForeground();
            Color background = isSelected?
                list.getSelectionBackground(): list.getBackground();
            // Set panel colors
            setForeground(foreground);
            setBackground(background);
            int col = 0;
            for(JLabel label : labels) {
                label.setBackground(background);
                label.setForeground(foreground);
                label.setText( String.valueOf(rowData[col++]) );
            }
            return this;
        }
      }
    
    }

    As an alternative, I thought that usiing a JComboBox 'ordinary' with the strings in column 1 as elements and you try to change the popup so that it displays and column 2.

    You can render the comboBox and the popup differently. Just check for an index of-1 for the drop-down list box.

    Different examples of how you can restore more than one column in a combo box. The example of "text pane" has been changed so that the drop-down list box shows only one column while the popup shows the two columns:

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.text.*;
    
    public class ComboBoxMultiColumn extends JFrame
    {
         public ComboBoxMultiColumn()
         {
              getContentPane().setLayout( new GridLayout(0, 2) );
    
              Vector items = new Vector();
              items.addElement( new Item("123456789", "Car" ) );
              items.addElement( new Item("23", "Plane" ) );
              items.addElement( new Item("345", "Train" ) );
              items.addElement( new Item("4567", "Nuclear Submarine" ) );
    
              //  Use a JTextArea as a renderer
    
              JComboBox comboBox1 = new JComboBox( items );
              comboBox1.setRenderer( new TextAreaRenderer(5) );
    
              getContentPane().add( new JLabel("TextArea Renderer") );
              getContentPane().add( comboBox1 );
    
              //  Use a JTextPane as a renderer
    
              JComboBox comboBox2 = new JComboBox( items );
              comboBox2.setRenderer( new TextPaneRenderer(10) );
    
              getContentPane().add( new JLabel("TextPane Renderer") );
              getContentPane().add( comboBox2 );
    
              //  Use a JPanel as a renderer
    
              JComboBox comboBox3 = new JComboBox( items );
              comboBox3.setRenderer( new PanelRenderer(50) );
    
              getContentPane().add( new JLabel("Panel Renderer") );
              getContentPane().add( comboBox3 );
    
              //  Using HTML
    
              JComboBox comboBox4 = new JComboBox( items );
              comboBox4.setRenderer( new HTMLRenderer() );
    
              getContentPane().add( new JLabel("HTML Renderer") );
              getContentPane().add( comboBox4 );
         }
    
         class Item
         {
              private String id;
              private String description;
    
              public Item(String id, String description)
              {
                   this.id = id;
                   this.description = description;
              }
    
              public String getId()
              {
                   return id;
              }
    
              public String getDescription()
              {
                   return description;
              }
    
              public String toString()
              {
                   return description;
              }
         }
    
         public static void main(String[] args)
         {
              JFrame frame = new ComboBoxMultiColumn();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
         }
    
         /*
         **  Tabs are easier to use in a JTextArea, but not very flexible
         */
         class TextAreaRenderer extends JTextArea implements ListCellRenderer
         {
              public TextAreaRenderer(int tabSize)
              {
                   setTabSize(tabSize);
              }
    
              public Component getListCellRendererComponent(JList list, Object value,
                   int index, boolean isSelected, boolean cellHasFocus)
              {
                   Item item = (Item)value;
                   setText(item.getId() + "\t" + item.getDescription());
                   setBackground(isSelected ? list.getSelectionBackground() : null);
                   setForeground(isSelected ? list.getSelectionForeground() : null);
                   return this;
              }
         }
    
         /*
         **  Tabs are harder to use in a JTextPane, but much more flexible
         */
         class TextPaneRenderer extends JTextPane implements ListCellRenderer
         {
              public TextPaneRenderer(int tabColumn)
              {
                   setMargin( new Insets(0, 0, 0, 0) );
    
                   FontMetrics fm = getFontMetrics( getFont() );
                   int width = fm.charWidth( 'w' ) * tabColumn;
    
                   TabStop[] tabs = new TabStop[1];
                   tabs[0] = new TabStop( width, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE );
                   TabSet tabSet = new TabSet(tabs);
    
                   SimpleAttributeSet attributes = new SimpleAttributeSet();
                   StyleConstants.setTabSet(attributes, tabSet);
                   getStyledDocument().setParagraphAttributes(0, 0, attributes, false);
              }
    
              public Component getListCellRendererComponent(JList list, Object value,
                   int index, boolean isSelected, boolean cellHasFocus)
              {
                   Item item = (Item)value;
    
                   if (index == -1)
                        setText( item.getDescription() );
                   else
                        setText(item.getId() + "\t" + item.getDescription());
    
                   setBackground(isSelected ? list.getSelectionBackground() : null);
                   setForeground(isSelected ? list.getSelectionForeground() : null);
                   return this;
              }
         }
    
         /*
         **  Use a panel to hold multiple components
         */
         class PanelRenderer implements ListCellRenderer
         {
              private JPanel renderer;
              private JLabel first;
              private JLabel second;
    
              public PanelRenderer(int firstColumnWidth)
              {
                   renderer = new JPanel();
                   renderer.setLayout(new BoxLayout(renderer, BoxLayout.X_AXIS) );
    
                   first = new JLabel(" ");
                   Dimension d = first.getPreferredSize();
                   d.width = firstColumnWidth;
                   first.setMaximumSize(d);
                   second = new JLabel();
                   renderer.add(first );
                   renderer.add(second );
              }
    
              public Component getListCellRendererComponent(JList list, Object value,
                   int index, boolean isSelected, boolean cellHasFocus)
              {
                   Item item = (Item)value;
    
                   first.setText( item.getId() );
                   second.setText( item.getDescription() );
    
                   renderer.setBackground(isSelected ? list.getSelectionBackground() : null);
                   renderer.setForeground(isSelected ? list.getSelectionForeground() : null);
    
                   return renderer;
              }
         }
    
         /*
         **  Use HTML to format the text
         */
         class HTMLRenderer extends DefaultListCellRenderer
         {
              private static final String START = "
    "; private static final String MIDDLE = ""; private static final String END = "
    "; public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); Item item = (Item)value; setText(START + item.getId() + MIDDLE + item.getDescription() + END); return this; } } }

Maybe you are looking for