Note that there are some explanatory texts on larger screens.

plurals
  1. POGridBagLayout, disappearing JList
    primarykey
    data
    text
    <p>I wrote simple java application. One window (JFrame ramka) containing 3 elements: JButton, JComboBox and container (which contain JList). I would like to rearrange positions of those elements, and it cause problems. I would like to use GridBagLayout, but when I do this, my container disappears(or it is 1px large -.-), also setSize works fine for JComboBox. And when I do not use any layout, container with JList is shown, but resizing JComboBox doesn't work, and everything is overlaping itself... generaly it looks like.. it doesn't look at all.</p> <p>here come my question: how, and what layout use to reorganise positions of my compnents and JFrame? i use NetBeans 7.2</p> <pre><code>package layouttest; import java.awt.*; import javax.swing.*; import javax.swing.JList; import java.util.ArrayList; import java.awt.*; import java.awt.GridBagLayout; import java.awt.event.*; import javax.swing.*; public class Layouttest { public static void main(String[] args) { JFrame ramka = new JFrame(); //ramka.setLayout(new GridLayout(4, 3)); //ramka.setLayout(new GridBagLayout()); String [] test = {"cos", "cos2", "cos3", "cos4", "cos5", "cos6", "cos7", "cos8", "cos9","cos10", "cos11", "cos12"}; ArrayList&lt;String&gt; myList = new ArrayList&lt;String&gt;(); myList.add("cos"); myList.add("cos2"); myList.add("cos3"); myList.add("cos4"); myList.add("cos5"); myList.add("cos6"); myList.add("cos7"); myList.add("cos8"); myList.add("cos9"); myList.add("cos10"); GridBagConstraints ogranicznik = new GridBagConstraints(); ogranicznik.insets = new Insets(5, 10, 5, 5); ogranicznik.gridx = 0; ogranicznik.gridy = 0; Container c = new Container(); ramka.setSize(500, 500); c.setSize(100,100); JList lista = new JList(myList.toArray()); JScrollPane sp = new JScrollPane(lista); JTextField txt = new JTextField("cos"); c.add(sp); sp.setSize(100,100); lista.setSize(100, 100); ramka.add(c); ramka.add(txt); String[] dropBoxList = {"uno", "due", "tre"}; final JComboBox listaRozwijalna = new JComboBox(dropBoxList); listaRozwijalna.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXX"); listaRozwijalna.revalidate(); listaRozwijalna.repaint(); ramka.add(listaRozwijalna); c.revalidate(); c.repaint(); ramka.revalidate(); ramka.setVisible(true); ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // TODO code application logic here } } </code></pre> <p>@EDIT i discovered that java has problem with showing container while using layout models...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload