Caffeinated
Caffeinated

Reputation: 12484

How do I prevent my java GUI buttons from shrinking (GIF included)?

I made a GIF of my situation:

enter image description here

Forgive the speed of it, I made it too fast

I thought that there was a function like repaint() or such? Is there a way to keep the buttons always fixed?

Here's where I add Buttons:

guiFrame.add(but2, BorderLayout.LINE_START);        
guiFrame.add(but, BorderLayout.CENTER);     
guiFrame.add(but3, BorderLayout.LINE_END);          
guiFrame.add(combo2, BorderLayout.NORTH);
guiFrame.setVisible(true);

Here's my code, alternatively here

thanks

Upvotes: 2

Views: 160

Answers (2)

Sage
Sage

Reputation: 15418

  1. Put your JTextArea inside a JScrollPane and add the scroll pane to your frame's content pane:

    textArea = new JTextArea(5, 20);
    JScrollPane scrollPane = new JScrollPane(textArea);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    
  2. Put your three buttons inside another JPanel: buttonPanel with suitable layout manager. Add this buttonPanel to the frame's content pane with BorderLayout.PAGE_END

    getContentPane().add(buttonPanel, BorderLayout.PAGE_END);
    

Upvotes: 4

mKorbel
mKorbel

Reputation: 109813

I thought that there was a function like repaint() or such? Is there a way to keep the buttons always fixed?

  • everything depends of used LayoutManager, for better help sooner post an SSCCE, short, runnable, compilable, caused a.m. issue

  • put floating JComponent to JScrollPane

Upvotes: 3

Related Questions