View unanswered posts | View active topics It is currently Sun May 28, 2017 9:23 pm

Reply to topic  [ 1 post ] 
 JSlider not aligning correctly 
Author Message

Joined: Mon Jun 15, 2009 5:25 pm
Posts: 2
Post JSlider not aligning correctly
Hi All,

I have a program where I have a jlabel and a jslider on the same line.
They are not lining up correctly.
I made a sample program to show what I am talking about.

Test one is how it is now
Test two is with two jsliders
Test three is how I think it should look using borderlayout to accomplish it.


package test;

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;

import net.miginfocom.swing.MigLayout;

public class MigSliderTest {
   public MigSliderTest(){
      JFrame frame = new JFrame();
      //JPanel panel = getTestPanel1();
      //JPanel panel = getTestPanel2();
      JPanel panel = getTestPanel3();
      Container container = frame.getContentPane();
      container.setLayout(new BorderLayout());
      container.add(panel, BorderLayout.CENTER);
      frame.setSize(400, 200);
   private JPanel getTestPanel1(){
      JPanel panel = new JPanel(new MigLayout("w 200","[][grow]",""));
      panel.add(new JLabel("Label:"));
      panel.add(new JSlider(), "span, grow, wrap");
      return panel;
   private JPanel getTestPanel2(){
      JPanel panel = new JPanel(new MigLayout("w 200","[][grow][]","[][][][][][][][]"));
      panel.add(new JSlider());
      panel.add(new JSlider(), "span, grow, wrap");
      return panel;
   private JPanel getTestPanel3(){
      JPanel panel = new JPanel(new BorderLayout());
      JPanel subPanel = new JPanel(new BorderLayout());
      subPanel.add(new JLabel("Label:"), BorderLayout.WEST);
      subPanel.add(new JSlider(), BorderLayout.CENTER);
      panel.add(subPanel, BorderLayout.NORTH);
      return panel;
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      new MigSliderTest();

Mon Jun 22, 2009 6:22 am
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.