BoxLayout

Is it posible to use fillers( Box.Filler) in other layouts than boxlayout?

itemTitleTextField = new JTextField (10);//<--change to 10, visibly smaller, change back later
newItemDescriptionPanel.add (secondCategoryAnimalCheckBox);
newItemDescriptionPanel.add (blankLabel);
newItemDescriptionPanel.add (itemTitleLabel);
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));//<--added, to take additional space
p.add(itemTitleTextField);//<--add textfield to panel
newItemDescriptionPanel.add (p);//<--add panel to boxlayout panel

Similar Messages

  • Can't use BoxLayout more than once in a class?

    I have a JPanel inside of a JPanel. I am using a BoxLayout
    manager on the main JPanel, and I used to use a GridLayout on the
    sub JPanel. Yesterday I changed the Layout Manager of the subPanel
    to BoxLayout, and now I get this strange error at runtime. Why can't I use
    2 Box Layouts? Why is Java trying to share them?
    Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared
            at javax.swing.BoxLayout.checkContainer(BoxLayout.java:408)
            at javax.swing.BoxLayout.invalidateLayout(BoxLayout.java:195)
            at java.awt.Container.invalidate(Container.java:851)
            at java.awt.Component.addNotify(Component.java:5398)
            at java.awt.Container.addNotify(Container.java:1852)
            at javax.swing.JComponent.addNotify(JComponent.java:4270)
            at java.awt.Container.addNotify(Container.java:1859)
            at javax.swing.JComponent.addNotify(JComponent.java:4270)
            at java.awt.Container.addNotify(Container.java:1859)
            at javax.swing.JComponent.addNotify(JComponent.java:4270)
            at java.awt.Container.addNotify(Container.java:1859)
            at javax.swing.JComponent.addNotify(JComponent.java:4270)
            at java.awt.Container.addNotify(Container.java:1859)
            at javax.swing.JComponent.addNotify(JComponent.java:4270)
            at java.awt.Container.addNotify(Container.java:1859)
            at javax.swing.JComponent.addNotify(JComponent.java:4270)
            at java.awt.Container.addNotify(Container.java:1859)
            at javax.swing.JComponent.addNotify(JComponent.java:4270)
            at javax.swing.JRootPane.addNotify(JRootPane.java:658)
            at java.awt.Container.addNotify(Container.java:1859)
            at java.awt.Window.addNotify(Window.java:395)
            at java.awt.Frame.addNotify(Frame.java:479)
            at java.awt.Window.pack(Window.java:413)
            at CDBTest.main(CDBTest.java:246)I need help.
    Thanks
    Josh

    hmm, the following's my code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class PreferencesPane extends JPanel {
    //Main pane to be added to the class
    private JTabbedPane mainPane;
    //the options pane
    private JPanel optionsPane;
    //the accounts list
    private JPanel accountsPane;
    //the personal information display
    private JPanel perInfoPane1;
    private JPanel perInfoPane2;
    //labels
    private JLabel usernameLabel;
    private JLabel newPassLabel;
    private JLabel confPassLabel;
    private JPanel separatorLabel;
    private JLabel nameLabel;
    private JLabel emailLabel;
    private JLabel titleLabel;
    private JLabel companyLabel;
    private JLabel homePhoneLabel;
    private JLabel workPhoneLabel;
    private JLabel cellPhoneLabel;
    private JLabel faxLabel;
    private JLabel homeAddLabel;
    private JLabel workAddLabel;
    private JLabel notesLabel;
    //Textfields
    private JTextField usernameField;
    private JPasswordField newPassField;
    private JPasswordField confPassField;
    private JPanel separatorField;
    private JTextField nameField;
    private JTextField emailField;
    private JTextField titleField;
    private JTextField companyField;
    private JTextField homePhoneField;
    private JTextField workPhoneField;
    private JTextField cellPhoneField;
    private JTextField faxField;
    private JTextArea homeAddField;
    private JTextArea workAddField;
    private JTextArea notesField;
    //Save information button
    private JButton saveInfoButton;
    private JPanel perInfoPane;
    public PreferencesPane() {
    optionsPane = new JPanel();
    accountsPane = new JPanel();
    //labels
    usernameLabel = new JLabel("Username:");
    newPassLabel = new JLabel("New Password:");
    confPassLabel = new JLabel("Confirm New Password:");
    separatorLabel = new JPanel();
    nameLabel = new JLabel("Name:");
    emailLabel = new JLabel("Email:");
    titleLabel = new JLabel("Title:");
    companyLabel = new JLabel("Company:");
    homePhoneLabel = new JLabel("Home Phone:");
    workPhoneLabel = new JLabel("Work Phone:");
    cellPhoneLabel = new JLabel("Cell Phone:");
    faxLabel = new JLabel("Fax:");
    homeAddLabel = new JLabel("Home Address:");
    workAddLabel = new JLabel("Work Address:");
    notesLabel = new JLabel("Notes:");
    //Textfields
    usernameField = new JTextField(20);
    newPassField = new JPasswordField(20);
    confPassField = new JPasswordField(20);
    separatorField = new JPanel();
    nameField = new JTextField(20);
    emailField = new JTextField(20);
    titleField = new JTextField(20);
    companyField = new JTextField(20);
    homePhoneField = new JTextField(20);
    workPhoneField = new JTextField(20);
    cellPhoneField = new JTextField(20);
    faxField = new JTextField(20);
    homeAddField = new JTextArea(10,20);
    workAddField = new JTextArea(10,20);
    notesField = new JTextArea(10,20);
    //Panel to contain the textfield and labels
    perInfoPane1 = new JPanel(new GridLayout(12,2));
    perInfoPane1.add(usernameLabel);
    perInfoPane1.add(usernameField);
    perInfoPane1.add(newPassLabel);
    perInfoPane1.add(newPassField);
    perInfoPane1.add(confPassLabel);
    perInfoPane1.add(confPassField);
    perInfoPane1.add(separatorLabel);
    perInfoPane1.add(separatorField);
    perInfoPane1.add(nameLabel);
    perInfoPane1.add(nameField);
    perInfoPane1.add(emailLabel);
    perInfoPane1.add(emailField);
    perInfoPane1.add(titleLabel);
    perInfoPane1.add(titleField);
    perInfoPane1.add(companyLabel);
    perInfoPane1.add(companyField);
    perInfoPane1.add(homePhoneLabel);
    perInfoPane1.add(homePhoneField);
    perInfoPane1.add(workPhoneLabel);
    perInfoPane1.add(workPhoneField);
    perInfoPane1.add(cellPhoneLabel);
    perInfoPane1.add(cellPhoneField);
    perInfoPane1.add(faxLabel);
    perInfoPane1.add(faxField);
    perInfoPane2 = new JPanel(new GridLayout(3,2));
    perInfoPane2.add(homeAddLabel);
    perInfoPane2.add(homeAddField);
    perInfoPane2.add(workAddLabel);
    perInfoPane2.add(workAddField);
    perInfoPane2.add(notesLabel);
    perInfoPane2.add(notesField);
    //save button
    saveInfoButton = new JButton("Save information");
    perInfoPane = new JPanel(new BoxLayout(perInfoPane,BoxLayout.Y_AXIS));
    perInfoPane1.setAlignmentX(Component.LEFT_ALIGNMENT);
    perInfoPane2.setAlignmentX(Component.LEFT_ALIGNMENT);
    saveInfoButton.setAlignmentX(Component.LEFT_ALIGNMENT);
    perInfoPane.add(perInfoPane1);
    perInfoPane.add(perInfoPane2);
    perInfoPane.add(saveInfoButton);
    //adds components to the TabbedPane
    mainPane = new JTabbedPane(JTabbedPane.LEFT);
    mainPane.add("Options",optionsPane);
    mainPane.add("Accounts",accountsPane);
    mainPane.add("Personal Information",perInfoPane);
    setLayout(new BorderLayout());
    add(mainPane,BorderLayout.CENTER);
    As you can see, the only time I use BoxLayout is the following line:
    perInfoPane = new JPanel(new BoxLayout(perInfoPane,BoxLayout.Y_AXIS));
    As far as I can tell, that's correct, but I'm still getting this at runtime:
    Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared
    Anyone have any ideas?

  • JPanel won't display in BoxLayout when adding components in different order

    For some reason when I run this code, the topPanel (made up of two panels which are all JLabels, JButtons, and JTextFields) does not display on the screen, but the investmentPanel (JTable within a JScrollPane) does. But when I add them in the reverse order, they both show up, but not in the order I want them to. The JPanel I am adding to is maximized so that shouldn't be an issue. Any thoughts of why this is happening?
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
    topPanel.add(companyInfoPanel);
    topPanel.add(tradePanel);
    add(topPanel);
    add(investmentPanel);

    Your best bet here is to show us your code. We don't want to see all of it, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem, in other words, an SSCCE (Short, Self Contained, Correct (Compilable), Example). For more info on SSCCEs please look here:
    http://homepage1.nifty.com/algafield/sscce.html

  • Add a JLabel below a JTextArea in a boxlayout

    I have a JTextArea in a JScrollPane in a GUI, and I'm using BoxLayout. Occasionally, I wish to add a JLabel to my JScrollPane, which works fine.
    However, since my BoxLayout is set to the Y_Axis layout, the JLabel always ends up being centered below the JTextArea, and I want it, as well as the JTextArea, to be aligned to the left. I know there is a LEFT_ALIGNMENT operator, but I am unsure of how to use it, although I've read the API for java.awt.Component.
    Also, my JTextArea has a maximum column size, but when the JLabel is displayed, the JTextArea stretches across my entire JScrollPane window. I've tried setting a maximum size, but for some reason that tends to cut off some text on the left side of the JTextArea.
    The JLabel will almost always be wider than the JTextArea. Perhaps that is causing some problems with BoxLayout?
    If there's any more information I should provide, please let me know.
    Thanks for any help you can provide,
    Dan
    Message was edited by:
    Djaunl

    Ok I figured out how the align the JLabel to the left:
    myJLabel.setAlignmentX(Component.LEFT_ALIGNMENT);However, I'm having an odd problem with my JTextArea. If my GUI displays the text normally, everything is fine. But once I add a JLabel to my JScrollPane that is wider than the view (i.e. so I need to scroll horizontally to see the entire JLabel), when I load more text, the text will not position itself within the JScrollPane view, and I will have to scroll over to see all of the text, which I do not want to do.
    Is there a way to keep the JTextArea at the same maximum column number, even though there is a JLabel below it that is much wider than the JTextArea should be?
    I get the feeling this isn't making sense. Here's the code to create my components:
    // Create min/max dimensions
              Dimension minimumSize = new Dimension(200, 500);
              Dimension maximumSize = new Dimension(500, 500);
                    Dimension buttonSize = new Dimension (125, 20);
                    int cols = 30;
              // Create Tree viewing pane
              JScrollPane treeView = new JScrollPane(tree);
              treeView.setMinimumSize(minimumSize);
              treeView.setMaximumSize(maximumSize);
              // Create HTML viewing pane 1
              final JPanel htmlView1 = new JPanel();
                    BoxLayout BL = new BoxLayout(htmlView1, BoxLayout.Y_AXIS);
                    htmlView1.setLayout(BL);
                    final JScrollPane htmlPane = new JScrollPane(htmlView1);
              htmlPane.setMinimumSize(minimumSize);
              htmlPane.setMaximumSize(maximumSize);
                    // Create text area1
                    final JTextArea textArea1 = new JTextArea();
                    textArea1.setLineWrap(true);
                    textArea1.setWrapStyleWord(true);
                    textArea1.setColumns(cols);
                    textArea1.setAlignmentX(Component.LEFT_ALIGNMENT);
                                            JLabel pic = new JLabel (new ImageIcon(new URL(DBQuery.list.get(1))));
                                            pic.setAlignmentX(Component.LEFT_ALIGNMENT);
                                            htmlView1.add(pic);Later in the code, I add textArea1 to htmlView1.
    I'm sorry if this is very confusing. If there is anything I can do to help, please let me know.

  • How to create a jdialog with boxlayout

    Hi,
    I was trying to create a jdialog as simple as plsql login dialog. In attempt to learn how should I proceed I downloaded and modified BoxLayoutDemo.java that is available from java's swing tutorial site:
    * BoxLayoutDemo.java is a 1.4 application that requires no other files.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    public class BoxLayoutDemo {
        static JDialog jdlg;
        public static void addComponentsToPane(Container pane) {
            pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
            addTextField(pane);
            addAButton("Button 1", pane);
            addAButton("Button 2", pane);
            addAButton("Button 3", pane);
            addAButton("Long-Named Button 4", pane);
            addAButton("5", pane);
        private static void addAButton(String text, Container container) {
            JButton button = new JButton(text);
            button.setAlignmentX(Component.CENTER_ALIGNMENT);
            container.add(button);
        private static void addTextField(Container container) {
            JTextField txt = new JTextField(20);
            //txt.setMaximumSize(new Dimension(100,20));
            txt.setPreferredSize(new Dimension(100,10));
            txt.setAlignmentX(Component.RIGHT_ALIGNMENT);
            //Border padding = BorderFactory.createEmptyBorder(20,20,5,20);
            //txt.setBorder(padding);
            container.add(txt);
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("BoxLayoutDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Set up the content pane.
            jdlg = new JDialog(frame);
            addComponentsToPane(jdlg.getContentPane());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
            jdlg.setPreferredSize(new Dimension(200,200));
            jdlg.pack();
            jdlg.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();
    }The funniest thing is every thing except the text box is ok. With or without the text box the buttons are shown appropriately i mean they dont stretch. But in case of the text field it seems like that the height of the textfield becomes 60 instead of 20. if I use txt.setMaximumsize(new Dimension(100,20)) then everything seems ok.
    Now it seems like swing has some fetish about textfields. Because even if I dont specify the size of the buttions they dont stretch themsleves but even if I specify the size of the text field and make it the first element so that the last element gets stretched if necessary without affecting it, it will defy the size instruction.Layout managers are really amazing!!!!!!!! and so helpful!!!!!!!!!

    not really sure what effect you want, but try this
        private static void addTextField(Container container) {
            JTextField txt = new JTextField(20);
            //txt.setMaximumSize(new Dimension(100,20));
            txt.setPreferredSize(new Dimension(100,10));
            txt.setAlignmentX(Component.RIGHT_ALIGNMENT);
            //Border padding = BorderFactory.createEmptyBorder(20,20,5,20);
            //txt.setBorder(padding);
            JPanel p = new JPanel();//<-------------
            p.add(txt);//<-------------
            //container.add(txt);//<-------------
            container.add(p);//<-------------
        }

  • Whoever updated BoxLayout must not know how to program in Java

    Why would you allow anyone to update their source that doesn't know what they are doing.
    Notice that BoxLayout is non-consistent with any other layouts.
    i.e. Why do you think that JPanel allows you to create a Layout when instantiating the object?.
    The way it is now, you have to call another method.
    Yeah, one method might not make a difference in performance but all the inconsistencies add up. Overhead....
    Yeah, I am the one that you screwed over - but whatever!
    Edited by: cosmic_string on Mar 6, 2008 5:55 PM
    Edited by: cosmic_string on Mar 6, 2008 5:56 PM

    I doubt that admin would read your concerns.
    This is not the appropriate forum to post this.

  • Center JComboBox in BoxLayout

    I try to center a single JComboBox in a JPanel with BoxLayout. But it is still left aligned. I use:
    jpanel.setLayout(new BoxLayout(jpanel,BoxLayout.X_AXIS));
    ...add(jpanel);
    jcombo.setAlignmentX(0.5F);
    jpanel.add(jcombo);
    What is missing?

    wow, it works, I'll give you my last two duke dollars. I should achieve new ones for my logins I expect.
    Now, x-centering seems only to be possible if aligned along y-axis. So for the other panels where I have to align along x-axis because I have more than one combo included I can't make a simple centering? Do I have to use invisible components to have some centering effects?

  • Align left panels inside BoxLayOut / Center a frame center screen

    Hi,
    I've googled for a good while now so now I'm posting the question I have not found a satisfactory answer. It may be that I've been searching by the wrong terms, because it's an easy thing in concept. This is a JSwing question and all terms below apply to that.
    I have a method which takes a container that has a BoxLayout manager. Each item I add is a new row, which is good. The bad thing is that each item is centered aligned. I'm adding a label and textfield into a panel which I then add to the container. I have tried .setAlignmentX to the label, textfield, panel, and all combination pertaining. I can not for the life of me do it. Please see below for pertinent code.
    public void addComponentsToPane(Container pane) {
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    JPanel user = new JPanel();
    JLabel userL = new JLabel("Username: ");
    JTextField userT = new JTextField(20);
    user.add(userL);
    user.add(userT);
    user.setAlignmentX(Component.LEFT_ALIGNMENT);
    I hate to put two questions in one thread, but I'm stuck and it's been a long weekend. How come frame.setLocationRelativeTo(null); doesn't set the frame to the center of the window. It's slightly off center; too far to the right and down.
    Thanks in advance for any help given by the community. I appreciate it and hope I haven't broken any guidelines for the forum.

    Go through the [url http://download.oracle.com/javase/tutorial/uiswing/layout/box.html]tutorial for BoxLayout where you will find working code samples. After that, if you still have a problem, post a [url http://mindprod.com/jgloss/sscce.html]SSCCE (Short, Self Contained, Compilable and Executable) that members can copy and run to see where you've slipped up.
    db

  • FlowLayout With BoxLayout

    Ok,
    I have a panel I'm using boxlayout to display the items vertically and it works great, but the problem is I want them to be centered horizontally within that panel as well. I can get the FlowLayout center code to work correctly and the BoxLayout to work, but I can't get them to work together. Does anyone know how to center horizontally using PAGE_AXIS with BoxLayout? Thanks much!

    Did you just post me a link to my own thread? Can
    anyone else illustrate how to use BoxLayout but have
    the items cenetered horizontally like FlowLayout?
    Thanks so much!I think camick just fell foul of a forum software bug. he's not in the habit of playing sarcastic pranks on people :-)
    try this I believe it's what he was pointing you at

  • More BoxLayout alignment issues

    Hi everybody,
    I'm trying to create a bar graph with BoxLayout, but I'm having a problem. The BoxLayout always orients the buttons in a line on the exact center of the panel, which can result in a lot of extra space. I'd like to have the line be off-center if possible, with the panel bounded by the largest positive/negative bars. I can't figure out how to do that, unfortunately. Also, some of the buttons seem to be cut off when pack() is called; that might be related to this, but I'm not sure.
    Here's a SSCCE of my problem, it can probabaly explain better than I can:
    import java.awt.Dimension;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class BoxLayoutTest {
         public BoxLayoutTest() {
              JPanel panel = new JPanel();
              BoxLayout layout = new BoxLayout( panel, BoxLayout.X_AXIS );
              panel.setLayout( layout );
              for( int i = 0; i < 9; i++ ) {
                   JButton button = new JButton();
                   Dimension size;
                   if( i % 2 == 0 ) {
                        size = new Dimension( 30, 20 * (i+1) );
                        button.setAlignmentY( JButton.TOP_ALIGNMENT );
                   else {
                        size = new Dimension( 30, 30 );
                        button.setAlignmentY( JButton.BOTTOM_ALIGNMENT );
                   button.setPreferredSize( size );
                   button.setMaximumSize( size );
                   panel.add( button );
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.add( panel );
              frame.pack();
              frame.setVisible( true );
         public static void main( String args[] ) { new BoxLayoutTest(); }
    }If anyone could help me out with this, I'd appreciate it.
    Thanks,
    Jezzica85

    import java.awt.Dimension;
    import javax.swing.*;
    public class BoxLayoutTest2 {
         public BoxLayoutTest2() {
              //  Easier way to use BoxLayout
              Box panel = Box.createHorizontalBox();
    //          JPanel panel = new JPanel();
    //          BoxLayout layout = new BoxLayout( panel, BoxLayout.X_AXIS );
    //          panel.setLayout( layout );
              for( int i = 0; i < 9; i++ ) {
                   JButton button = new JButton();
                   Dimension size;
                   if( i % 2 == 0 ) {
                        size = new Dimension( 30, 20 * (i+1) );
                        button.setAlignmentY( JButton.TOP_ALIGNMENT );
                   else {
                        size = new Dimension( 30, 30 );
                        button.setAlignmentY( JButton.BOTTOM_ALIGNMENT );
                   button.setPreferredSize( size );
                   button.setMaximumSize( size );
                   button.setMinimumSize( size );  // this was the key
                   panel.add( button );
              //  Used to distribute extra vertical space equally
              Box vertical = Box.createVerticalBox();
              vertical.add( Box.createVerticalGlue() );
              vertical.add( panel );
              vertical.add( Box.createVerticalGlue() );
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    //          frame.add( panel );
              frame.add( vertical ); // added
              frame.pack();
              frame.setVisible( true );
         public static void main( String args[] ) { new BoxLayoutTest2(); }
    }

  • Canvas, paint(), and FlowLayout/BoxLayout

    Has anyone encountered an error of paint() not being called when placed in a Container with a FlowLayout or a BoxLayout? This has been a recurring issue for me.
    {=^)                                                                                                                                                                                                                                                                                                                                               

    Anyone?
    {=^)                                                                                                                                                                                                                                                   

  • Layout centering issue with BoxLayout

    The code is two BoxLayout panels placed in a frame with FlowLayout.
    I cannot get the second panel's label to be centered. I purposely made both panels identical. Any ideas what I am missing?
    import java.awt.*;
    import javax.swing.*;
    public class MVCtest extends JFrame {
         public MVCtest() {
              getContentPane().setLayout(new FlowLayout());
              JTextField controller = new JTextField(10);          
              JLabel controllerLabel = new JLabel("Controller");
              JPanel controllerPanel = new JPanel();
              controllerPanel.setLayout(new BoxLayout(controllerPanel, BoxLayout.Y_AXIS));
              controllerPanel.setBorder(BorderFactory.createEtchedBorder());
              controllerPanel.add(controllerLabel);
              controllerLabel.setAlignmentX(controllerLabel.CENTER_ALIGNMENT);
              controllerPanel.add(Box.createVerticalStrut(10));
              controllerPanel.add(controller);
              JTextField view = new JTextField(10);     
              JLabel viewLabel = new JLabel("Controller");
              JPanel viewPanel = new JPanel();
              viewPanel.setLayout(new BoxLayout(viewPanel, BoxLayout.Y_AXIS));
              viewPanel.setBorder(BorderFactory.createEtchedBorder());
              viewPanel.add(viewLabel);
              viewPanel.setAlignmentX(viewLabel.CENTER_ALIGNMENT);
              viewPanel.add(Box.createVerticalStrut(10));
              viewPanel.add(view);
              getContentPane().add(controllerPanel);
              getContentPane().add(viewPanel);
         public static void main(String[] args) {
              JFrame.setDefaultLookAndFeelDecorated(true);
              MVCtest frame = new MVCtest();
              frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
              frame.setSize(400,400);
              frame.setVisible(true);
    }Thanks,
    Lance

    Problem solved, yet not understood.
    I posted the question and now eliminated the issue.
    I simply cut and pasted the first panel code over the second panel's code. I then renamed the variables and the problem went away.
    I don't know why because I didn't see any problem with the first code.
    Thanks to any and all who committed brain power to this problem.
    Lance

  • Boxlayout question

    hey all
    i have a jfame that have a panel that have a y-axis boxlayout, in this panel i have another panel that have an x-axis boxlayout, in this panel i added a jlabel and a jtextfield but the problem is that those two components appear in the center of the panel, i tried setalignmentx() but it doesn't work...
    how to make the two component with left alignment???
    please help
    thanks in advance

    for all who are interested in a solution, here is the solution that i came up with
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    public class GUI extends JFrame implements ActionListener {
        public GUI() {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setTitle("DVD rental center");
            setSize(1000, 700);
            setLocation(20, 20);
            initializeMenuBar();
            initializeGUI();
        public void initializeGUI() {
            JTabbedPane tp = new JTabbedPane(JTabbedPane.LEFT);
            getContentPane().add(tp);
            tp.addTab("Rent Fees", new RentFeesGUI());
        public void initializeMenuBar() {
            JMenuBar menuBar = new JMenuBar();
            JMenu fileMenu = new JMenu("File");
            JMenuItem exitItem = new JMenuItem("Exit");
            exitItem.setActionCommand("exit");
            exitItem.addActionListener(this);
            fileMenu.add(exitItem);
            menuBar.add(fileMenu);
            this.setJMenuBar(menuBar);
        public static void main(String[] args) {
            GUI g = new GUI();
            g.setVisible(true);
         * Invoked when an action occurs.
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equalsIgnoreCase("exit"))
                System.exit(0);
    class RentFeesGUI extends JPanel implements WindowListener {
        private JLabel rentFee = new JLabel("Rent Fees ");
        private JLabel lateFee = new JLabel("Late Fees ");
        private JTextField rentFeeField = new JTextField(10);
        private JTextField lateFeeField = new JTextField(10);
        private final int HORIZONTAL_SPACING = 600;
        private final int VERTICAL_SPACING = 700;
        private final int SMALL_VERICAL_SPACING = 10;
        private final int FONT_SIZE = 20;
        private Font f = new Font("Times New Roman", Font.BOLD, FONT_SIZE);
        public RentFeesGUI() {
            setupComponents();
            setupFonts();
            initializeGUI();
        public void setupFonts() {
            rentFee.setFont(f);
            lateFee.setFont(f);
            rentFeeField.setFont(f);
            lateFeeField.setFont(f);
        public void setupComponents() {
            rentFeeField.setBorder(BorderFactory.createLoweredBevelBorder());
            lateFeeField.setBorder(BorderFactory.createLoweredBevelBorder());
        public void initializeGUI() {
            rentFeeField.setEditable(false);
            lateFeeField.setEditable(false);
            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
            Box b1 = new Box(BoxLayout.LINE_AXIS);
            b1.add(rentFee);
            b1.add(rentFeeField);
            b1.add(Box.createHorizontalStrut(HORIZONTAL_SPACING));
            add(b1);
            add(Box.createVerticalStrut(SMALL_VERICAL_SPACING));
            Box b2 = new Box(BoxLayout.LINE_AXIS);
            b2.add(lateFee);
            b2.add(lateFeeField);
            b2.add(Box.createHorizontalStrut(HORIZONTAL_SPACING));
            add(b2);
            add(Box.createVerticalStrut(VERTICAL_SPACING));
        public void setupButtons() {
            //To change body of implemented methods use File | Settings | File Templates.
        public void resetFields() {
            //To change body of implemented methods use File | Settings | File Templates.
         * Invoked the first time a window is made visible.
        public void windowOpened(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
         * Invoked when the user attempts to close the window
         * from the window's system menu.
        public void windowClosing(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
         * Invoked when a window has been closed as the result
         * of calling dispose on the window.
        public void windowClosed(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
         * Invoked when a window is changed from a normal to a
         * minimized state. For many platforms, a minimized window
         * is displayed as the icon specified in the window's
         * iconImage property.
         * @see java.awt.Frame#setIconImage
        public void windowIconified(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
         * Invoked when a window is changed from a minimized
         * to a normal state.
        public void windowDeiconified(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
         * Invoked when the Window is set to be the active Window. Only a Frame or
         * a Dialog can be the active Window. The native windowing system may
         * denote the active Window or its children with special decorations, such
         * as a highlighted title bar. The active Window is always either the
         * focused Window, or the first Frame or Dialog that is an owner of the
         * focused Window.
        public void windowActivated(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
         * Invoked when a Window is no longer the active Window. Only a Frame or a
         * Dialog can be the active Window. The native windowing system may denote
         * the active Window or its children with special decorations, such as a
         * highlighted title bar. The active Window is always either the focused
         * Window, or the first Frame or Dialog that is an owner of the focused
         * Window.
        public void windowDeactivated(WindowEvent e) {
            //To change body of implemented methods use File | Settings | File Templates.
    }

  • BoxLayout mystery.

    Usually I try to paint everything by myself, but its out of my hands in this case. It all seem to easy at first: I have a JPanel with
       JPanel W=new JPanel();
       W.setLayout(new BoxLayout(W,BoxLayout.Y_AXIS));To this "W" I keep adding JComponents, first its a JTextArea, than is an W.add() with JScrollPane holding a JTable. I pack the JFrame holding my W and what I see is that the frame is too small to hold the whole table. The table appears without one or two rows and I have to scroll it a bit. Its just optics, but I am puzzled, why is that so??
         [top of the frame]
           JText--------JText
           JTable           ^
               ....         |  <- Scroll bar
           JTable           v
                       (some empty space, like with vertical glue
         [bottom of the frame]Even if I increase the vertical size of the window, Java adds south of bottom table a lot of free space, prior to ever increasing the place for the table so that the vertical scroll bar vanishes. Of course I have spend some time on adding Box vertical glue, rigid space JSeparators, setting setPreferredSize(), reading Sun's tutorial, reading chapter in 4 in Robinson/Vorobiev Swing book, reading Geary and so on. All to no avail. Either it's a bug, or I do miss some fundamental understanding to how this Layout works.
    I wonder if some of you could help with a hint to a good reading about this issue, or with a hint of how to do solve it.
    Thanks,
    Thomas
    PS: Do you use TeX, Don Knuths system? It is really powerful, and layout for paragraphs is extremely difficult and flexible. But its manageable. You know what all these hss and vss glue elements will do, if properly used. Knuth/Plassman wrote ingenious algorithms for paragraph split. Complex, but correct. This is not so with Java. Its always down to puzzling and experimenting. Its like a ton of bugs atop of each other, and special cases. As if only their examples would work fine, but not a different case in your code. If I can, I use only one JPanel, one JScrollPane and I draw everything by myself. It saves me time!

    Use advanced layout managers such as FormLayout or GroupLayout which are much better suited for non-trivial UIs.
    kirillg
    Why are you wasting his time with such a stupid answer? He didn't ask about using a different layout, he asked about a problem he is having with BoxLayout. You need to learn to read.
    ThomasH_usually:
    A better way to tackle this is for you to build a small example app for people to try out to see whether we get the same behavior. If we do then we will be able to help you and make changes in the context of the program to hopefully solve the problem.
    In the web deployment, Java is very on the defensive compared to Flash solutions. The reason is its traditionally abysmal performance, especially the start of JVM is a "one minute of hard drive rattling," and usually the look of the GUI is very crude.
    If you mean web development as in applets, Sun has pretty much given up in trying to compete in this sector. There's no market in it for them anyways, since others are doing things much better and have a much richer toolset. Swing can still be used in an applet and that's about as far as it goes. However, Java is very well positioned for server-side code. Even desktop applications have come a long way. I write the UI for a large-scale desktop app and you wouldn't know it was written in Java.
    I think a lot of trouble trying to create a UI in Java is a that the pattern is different than a plain backend app. Swing controls are mostly self sufficient, well designed, and the MVC architecture is easy to use, but only once you get used to it. You'd be surprised how flexible and robust the api really is once you get into it.

  • Custom BoxLayouted component

    Hello Flex team and members.
    I'm trying to create a custom component using a BoxLayout (horizontal) . This component should display a linkbutton (iconized) along with a label. I wanted to use a BoxLayout to easy up all the positionning thing. So i copied the Box class and kept only the important thing to me.
    Here is what i have:
    package common
      import flash.events.Event;
      import flash.events.MouseEvent;
      import mx.containers.BoxDirection;
      import mx.containers.utilityClasses.BoxLayout;
      import mx.controls.Label;
      import mx.controls.LinkButton;
      import mx.core.Container;
      import mx.core.IUIComponent;
      public class TagLabel3 extends Container
         private var layoutObject:BoxLayout = new BoxLayout();
         [Embed(source="cancel.png")]
         protected var iconSymbol:Class;
         protected var tagLabel:Label;
         protected var closeButton:LinkButton;
         private var labelChanged:Boolean = false;
         private var _displayCloseButton:Boolean = true;
         private var _text:String;
         public function TagLabel3()
             super();
             layoutObject.target = this;
             layoutObject.direction = BoxDirection.HORIZONTAL;
             setStyle("cornerRadius", 4);
             setStyle("borderStyle", "solid");
             setStyle("borderThickness", 2);
             setStyle("backgroundColor", "#D4D4D4");
             setStyle("verticalAlign", "middle");
             // other setStyle()...
         override protected function createChildren():void
             super.createChildren();
             if (!closeButton)
               closeButton = new LinkButton();
               closeButton.setStyle("icon", iconSymbol);
               closeButton.addEventListener("heightChanged",
                  function (e:Event):void {
                      minHeight = closeButton.height + 10;
               addChild(closeButton);
             if (!tagLabel)
               tagLabel = new Label();
               addChild(tagLabel);
         override protected function commitProperties():void
             if (closeButton.visible != displayCloseButton)
               closeButton.includeInLayout = displayCloseButton;
               closeButton.visible = displayCloseButton;
         override protected function measure():void
             super.measure();
             layoutObject.measure();
         override protected function updateDisplayList(unscaledWidth:Number,
                                                       unscaledHeight:Number):void
             super.updateDisplayList(unscaledWidth, unscaledHeight);
             layoutObject.updateDisplayList(unscaledWidth, unscaledHeight);
             if (labelChanged)
                  tagLabel.text = text;
                  labelChanged = false;
         public function get text():String
             return _text;
         public function set text(value:String):void
             if (_text != value)
                 _text = value;
                 labelChanged = true;
                 invalidateSize();
                 invalidateDisplayList();
         public function get displayCloseButton():Boolean
             return _displayCloseButton;
         public function set displayCloseButton(value:Boolean):void
             if (_displayCloseButton != value)
                 _displayCloseButton = value;
                 invalidateProperties();
                 invalidateSize();
                 invalidateDisplayList();
    And now I am facing 2 problems:
    - when i play with the 'text' and 'displayCloseButton' properties, the things are being updated correctly but not the size of the whole container. How can i asked the layout to resize correctly.
    - the initial style is taking very long to initialize. I can really first see my container with no border and background color (but with the inner component displayed) and then 1.5 sec later the style is being set.
    I first did the same component by extending an HBox but i didn't want the user to be able to wrongly add something to the HBox by calling addChild on my component.
    Thank you

    Hi Evgeny,
    Try by clearing the browser cache and the [navigation cache|http://help.sap.com/saphelp_nw04/helpdata/en/a2/19edcf16474a9798a5681ce4fe4b25/frameset.htm]
    Hope this helps.
    Cheers!
    Sandeep Tudumu

Maybe you are looking for

  • Help! Why is the Pre's speaker ringing an incoming call when I have a headset on?

    Hi all, I just had the most embarrassing thing happen to me today. I was listening to some music on my Pre with the headset (that came with the Pre), and I received an incoming call. I heard it ring and answered the call, no problem what I thought! W

  • Why did my Windows 8 computer stop recognizing my ICD-PX820 to upload files?

    I have been using my Sony ICD-PX820 recorder with my Lenovo Idea Pad, which I purchased a year ago running Windows 8 (which has since updated to Windows 8.1) I have been able to plug my recorder into this computer, using this OS, to upload audio file

  • [SOLVED] Starting Full System Upgrade... There Is Nothing To Do

    "Starting Full System Upgrade... There Is Nothing To Do" is the only message I have ever seen when using pacman -Syu.  I have no problem installing files but pacman cannot seem to EVER find updates to anything.  Even when I know that a package has be

  • JSP Session in a Javascript Window

    When I open a javascript window (with window.open) and use session cookies everything works. In the new javascript window I have no problems to navigate. After disabling cookies I tried to open the javascript window again and get the following errorm

  • Number ranges in crm

    What kind of number ranges  we maintain normally when we are downloading BPs from r3 to crm . EX: I m downloading account groups in r3 to crm for which external number ranges were maintained in r3.Do i need to maintain External number ranges or Inter