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

Similar Messages

  • 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

  • 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);//<-------------
        }

  • Can't work FlowLayout with a JPanel, but can with contentPane...

    Hi,
    I usually use setBounds to layout my components but I am trying FlowLayout and GridLayout this time. I tried FlowLayout and got it to work when not using a JPanel. But when I try adding the JTextField to a JPanel like in the code below, the JTextField doesn't appear and only the yellow background appears. I don't know why. Thanks for your help.
           Container contentPane = getContentPane();
           contentPane.setBackground( Color.YELLOW );
           registerJPanel = new JPanel();
           registerJPanel.setLayout(new FlowLayout());
           usernameloginJTextField = new JTextField("hi");
           registerJPanel.add(usernameloginJTextField);
           setTitle( "Application");
           setSize( 400,400);
           setVisible( true );

    know how i can put each new component on a new line?
    registerJPanel.setLayout(new GridLayout(0,1));

  • BoxLayout: components with different alignmentX

    Hi all. Java newbie here.. Here's what I'm trying to do: Use BoxLayout to "left-align" three components, and have one component at the bottom centered at its container/frame.
    Something like this:
    | ( One )        |
    | ( Two )        |
    | ( Three )      |
    |     ( Four )   |
    `----------------'I want the Fourth component to be exactly in the center of the frame, and the others to be left-aligned to the frame. Here's the code:
    JButton b1 = new JButton("One");
    JButton b2 = new JButton("Two");
    JButton b3 = new JButton("Three");
    JButton b4 = new JButton("Four");
    b1.setAlignmentX(Component.LEFT_ALIGNMENT);
    b2.setAlignmentX(Component.LEFT_ALIGNMENT);
    b3.setAlignmentX(Component.LEFT_ALIGNMENT);
    b4.setAlignmentX(Component.CENTER_ALIGNMENT);
    // Add them all to container with BoxLayout.PAGE_AXISAccording to Sun's tutorial, fixing alignment problems can be done by setAlignmentX. Obviously, I didn't understand their documentation because the buttons come out differently.
    Any fix for this? Thanks for the help in advance.
    Message was edited by:
    astigmatik

    Just a quick note :
    In the doco for it says :
    setAlignmentX - sets the vertical alignment
    setAlignmentY - sets the horizontal alignment
    I think you want Y and not X
    I do want X because Y refers to TOP/CENTER/BOTTOM_ALIGNMENT, and I'm looking for LEFT/RIGHT/CENTER_ALIGNMENT. It is in the "Fixing Alignment Problems" (http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html#align).

  • Help needed with a layout problem

    I'm trying to build a JTabbedPane where each tab has a grid of buttons. The number of buttons is variable, and I'd like the buttons to flow sort of like with FlowLayout, with four columns. I need all the buttons to be the same size, even across tabs. I tried GridLayout, which doesn't work when I have too few buttons to fill a row. It fails in different ways, depending on how I set things up. If I try to set the layout to GridLayout(0, 4) (four columns), then if one tab has one row and another has two, the buttons on the one-row tab expand vertically to the height of the two-row tab. If I try GridLayout(2,4), then if a tab has only one button, it expands horizontally to the maximum width of any of the tabs. (It also has the further problem that if the maximum number of buttons on any tab is 6, they are placed in a 2x3 array; I'm trying to get them to be 4 buttons on the first row and 2 on the second.)
    I'm hoping there's a standard layout manager that can do the job, but I'm not too familiar with the Swing manager classes. Can I get what I want without writing my own layout manager?
    Thanks,
    Ted Hopp
    [email protected]

    I didn't think it was specifically a Swing question.Well, its either Swing or AWT, people who develop GUIs are the ones who are going to have experience using layout managers.
    but if someone can point the way to how to do this with GridBagLayout, nested containersSince you finished reading the tutorial, what have you tried? You've explained your problems using a single layout manager, so what problems are you having using nested layout managers?
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • 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.

  • 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?

  • 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(); }
    }

  • 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.

  • Help with TreeCellRenderer

    I am trying to create a JTree node with a JTable. I see only one line of data from JTable/JTables at the JTree node. What can I change so that it displays the whole JTable.
    And I don't see the default tree node Icons too atall folder like Icon if leaf nodes are there and dot like Icon if the node is a leaf. I see only the JTables for each node. What can I change so that I can see the Icons too.
    I have the following in the createnode() method.
    public void createNodes() {
    DefaultMutableTreeNode[] nodes = new DefaultMutableTreeNode[5];
    nodes[0] = new DefaultMutableTreeNode(table1);
    nodes[1] = new DefaultMutableTreeNode(table2);
    nodes[2] = new DefaultMutableTreeNode(table3);
    nodes[0].add(nodes[1]);
    nodes[0].add(nodes[2]);
    jTree1 = new JTree(nodes[0]);
    jTree1.setCellRenderer(new NodeRenderer());
    I have the following in the NodeRenderer
    public class NodeRenderer implements TreeCellRenderer {
    private JTable myTable;
    private JComponent renderer;
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    if((value instanceof DefaultMutableTreeNode)){
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    renderer = (JComponent)node.getUserObject();
    return renderer;
    Thanks.

    rxyz, i think you missed the point here, those icons are part of cellrenderer. so, if you want to see them, put them there. defaultTreeCellRenderer extends from JLabel and those icons are set with setIcon. now that you are using some JComponent(what ever it is) for rendering, it is up to you to put those icons there. so, my idea would be use a custom component where you can have an icon on lefthandside and JTable(may be flowlayout with some insets should do the trick) on right hand side,and render the tree with that component.

  • Why are Box and BoxLayout so awful?

    Box and BoxLayout would actually be useful if they weren't so poorly designed and implemented.
    1. Until JSE 1.4, Box was a subclass of Container instead of JComponent, which meant you couldn't put a border around it.
    2. Why does the constructor for BoxLayout need the container its managing as a parameter? The other layout classes don't.
    3. And the big problem with BoxLayout (and Box) is thay they often screw up the layout of their components, limiting their usefullness.
    It's as though Box and BoxLayout were an afterthought, and low priority on the list of things to fix.

    I've used it extensively since 1.3 without problems...

  • Multiline flow layout question

    I have a panel with BoxLayout that has a panel with flow layout:
    class PanelA{
            private JPanel panel1 = createPanel1();
            private JPanel panel2 = .....
            public PanelA() {
                    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                    add(panel1);
                    add(panel2);
            private JPanel createPanel1(){
                       JPanel p = new JPanel ();
                       p.setLayout (new FlowLayout(FlowLayout.LEADING));
    }I want to realize such behavior:
    When I add a label to panel1 and this label can't be shown because panel1 has no free space it should show this label on the next line. I know that flow layout is multiline and I see a new label on the next line if I dodn't add panel2. But I added panel2 and I see only one line of panel1.

    public class FileTablePanel extends JPanel {
        private FileTable fileTable;
        private NavigationBar navigation;
        public FileTablePanel() {
            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
            addFileTable();
            addNavigationBar();
        private void addFileTable() {
            fileTable = new FileTable(ClientModel.SINGLETON.getFileTableModel());
            fileTable.getColumnModel().getColumn(0).setPreferredWidth(206);
            fileTable.getColumnModel().getColumn(1).setPreferredWidth(45);
            fileTable.getColumnModel().getColumn(2).setPreferredWidth(55);
            fileTable.getColumnModel().getColumn(3).setPreferredWidth(85);
            fileTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            fileTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
            JScrollPane sp = new JScrollPane(fileTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            sp.setBorder(new EmptyBorder(0, 0, 0, 0));
            setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
            add(sp);
        private void addNavigationBar() {
            navigation = new NavigationBar();
            add(navigation);
        private class NavigationBar extends JPanel {
         public NavigationBar (){
                 FlowLayout layout = new FlowLayout(FlowLayout.LEADING);
                 setLayout(layout);
             * Changes navigation bar when table changes
             * @param e
            public void tableChanged(TableModelEvent e) {
                removeAll();
                fill();
                revalidate();
                repaint();
            private void fill() {
                FileTableModel t = (FileTableModel) fileTable.getModel();
                String[] s = t.getFolderPath();
                //add all links
                for (int i = 0; i < s.length; ++i){
                    CLink link = new CLink(new GoUpAction(times), "", "");
                    link.setText(message);
                    add (link);
    }

  • Aligning JLabel text...

    I have searched but I haven't been able to use anything successfully as of yet. I am writing my first gui with swing, and I want to have some text at the top that explains what is going on.
    I basically want the text at the top to be justified of center aligned. I tried using HTML tags, but that failed miserably. If someone could please help me out, I would be very grateful. Here is what I have:
    pmFrame = new JFrame( "Pattern Matcher" );
              pmFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              pmFrame.setResizable( false );
              //pmFrame.setSize( new Dimension( 250, 120 ) );
              Container contentPane = pmFrame.getContentPane();
        SpringLayout layout = new SpringLayout();
        contentPane.setLayout(layout);
              infoLbl = new JLabel( "<HTML>Hello world.</HTML>" );
              infoLbl.setAlignmentX( Component.CENTER_ALIGNMENT );
              infoLbl.setAlignmentY( Component.CENTER_ALIGNMENT );thanks

    I am writing my first gui with swingStart by reading up on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]Layout Managers. Learn to use the simple layout managers first (BorderLayout, FlowLayout, GridLayout, BoxLayout). Remember LayoutManagers can be nested. Then graduate to the more complex(SpringLayout, GridBagLayout).
    Here is a simple example using the default BorderLayout:
    JLabel center = new JLabel("Center Me");
    center.setHorizontalAlignment(JLabel.CENTER);
    getContentPane().add(center, BorderLayout.NORTH);

  • Maximizing JPanel inside a JFrame

    Hi guys. I have a jpanel inside a part of a jframe (1/4 of it) and I want to do two things
    1) Suppose I have a 'maximize' button inside this jpanel. I want when I press this button to make the jpanel take up the whole jframe's space instead of just 1/4 of it.
    2) When I maximize the jframe ( completely different than before) the jpanel's size remains the same. What I want is to make it take as much space as it "deserves" - 1/4 of the jframe.
    Could anyone help with these things? Thanks in advance

    I am only interested at (1) now. So what I have is a jpanel with flowlayout and two components inside. Another jpanel with flowlayout with a textpane inside and a jpanel with boxlayout that contains the two panels (placed vertically). Finally a jframe that contains this jpanel

Maybe you are looking for

  • Embedding Google earth in Java Application

    I have developed a java application with help of wings i wanna embed google earth can sum1 guide from were to proceed plz

  • Doubt in bapi_goodsmvt_create?

    hi experts, i am Creating a GOODS RECEIPT using BAPI w.r.t PO. my problem is for an order 12 qun is there but iam passing all parameters to BAPI but i have created 4 times GOODS RECEIPT for each time 2 qun .Now when iam trying to create for remaining

  • Failed deploy of javamail

    project builds without error I included javamail in project libraries deployment fails with these errors Invoking loadjava on connection 'Connection1' with arguments: -order -resolve -thin errors : class Mail ORA-29521: referenced name javax/mail/int

  • Best sequence setting for Sony HXR-NX5U (1920x1080)? Also, why use Sony Content Browser?

    Hello, I'm using Premiere CS 5.0 and I am hoping to find a sequence setting that doesn't require me to render footage from my new camera, a Sony HXR-NX5U.  Can anyone help me out?  Also, does anyone use Sony's Content Browser?  If so, why?  It seems

  • Loading Images with 1.3.1 Problem

    Hi! I've got a couple of swing applets that use Images. One uses the images for icons and one just draws the images. The images are loaded from jar files. Using version 1.3.0, everything works fine. When I load the applet using 1.3.1 or 1.4, however,