Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
GridBagLayout
Maiquel knechtel
Greenhorn
Posts: 12
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello everybody,
I would like to position the JLabel JList side but with a space between them
tracking code
package teste; /* * GridBagLayoutDemo.java requires no other files. */ import java.awt.*; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; public class GridBagLayoutDemo { final static boolean shouldFill = true; final static boolean shouldWeightX = true; final static boolean RIGHT_TO_LEFT = false; public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); } JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); if (shouldFill) { //natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Jane Doe"); listModel.addElement("John Smith"); listModel.addElement("Kathy Green"); JList jlist = new JList(listModel); c.ipady = 200; c.ipadx = 20; c.gridx = 40; c.gridy = 100; pane.add(jlist, c); JLabel label = new JLabel("Origem"); c.ipady = 10; c.ipadx = 280; c.gridx = 60; c.gridy = 60; pane.add(label, c); } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("GridBagLayoutDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. addComponentsToPane(frame.getContentPane()); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Kemal Sokolovic
Bartender
Posts: 825
5
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Did you go through
How to Use GridBagLayout
first? There is an example with exactly what you're looking for (applied to buttons).
The quieter you are, the more you are able to hear.
Campbell Ritchie
Marshal
Posts: 79177
377
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Also find out about the GBC class, which you can find
here
, along with a link to a classic
tutorial
. The tutorial works better after a few drinks
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
GridBagLayout Problem
Need help with addActionListener
Can't get PaintComponent to work :(
GridBagLayout and JFrame
gridlayout with combo box
More...