Solved

Layout related query

Posted on 2004-08-12
4
229 Views
Last Modified: 2010-03-31
Hi all,

i have few Jcheckboxes to be added to the left side of a toolbar and some jbuttons
that are to be added at right to same jtoolbar.
The main idea is to use some layout manager that can do this.

Actually iam trying make a Login Window. In that login window i want along with the login and cancel buttons there should be a option for Saving Password (a check box).
So that check box should appear on extreme left side and other 2 buttons on extreme right side. I want to use JToolBar to place the buttons and checkbox

Thanx
0
Comment
Question by:Harpreet79
  • 2
4 Comments
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Take a look here for some sample code:

http://javaalmanac.com/egs/javax.swing/toolbar_ToolBar.html
0
 

Author Comment

by:Harpreet79
Comment Utility
hi
actually i tried that example but the layout didnt work the wayi wanted
cud pls suggest some other example
thanx
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
0
 
LVL 6

Accepted Solution

by:
expertmb earned 50 total points
Comment Utility
try this. it may help.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class JToolBarExample1 extends JFrame
                             {
  private JToolBar toolbar;
  private JCheckBox labelBox;

  public static void main(String[] args) {
    new JToolBarExample1();
  }

  public JToolBarExample1() {
    super("JToolBar Example");
    Container content = getContentPane();
    content.setBackground(Color.white);
    toolbar = new JToolBar();
    content.add(toolbar, BorderLayout.SOUTH);
    labelBox = new JCheckBox("Check Box");
    labelBox.setHorizontalAlignment(SwingConstants.CENTER);
    toolbar.add(labelBox);
    //LOOK HERE
    JPanel panel = new JPanel();
    panel.setSize(100, 10);
   //##########
    toolbar.add(panel);
    toolbar.add(new JButton("Login"));
    toolbar.add(new JButton("Cancel"));
    content.add(new JTextArea(10,30), BorderLayout.CENTER);
    pack();
    setVisible(true);
  }

}

mb...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now