Results 1 to 2 of 2
- 11-12-2012, 11:39 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 44
- Rep Power
- 0
Aligning and Stretching components (i.e. JButton)
I am trying to setSize for the Buttons so that they will stretch across their respective cell of the GridBagLayout. Now, I have looked through the API and have hunted down a few setSize. I know it isn't Java, so what have I overlooked perhaps that has been causing me to pull my hair out.
The program has no errors, but I am just not grasping the setSize (as well as aligning components). Can someone smack me on the back of the head and point me in a general direction as to where I might have strayed.Java Code:import java.awt.*; import javax.swing.*; public class BillFlipper { public static int winW = 400; public static int winH = 850; public static int items = 1; // Includes Title and all Flippers public static int rowH = winH/items; public static void addComponentsToPanel(Container pane){ pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JLabel title = new JLabel("Bill Swapper"); title.setFont(new Font("sansserif", Font.BOLD, 30)); title.setSize((winW-100), (winH/items)); counter(); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; pane.add(title, c); JLabel needL = new JLabel("NEED TO PAY |"); needL.setHorizontalAlignment(SwingConstants.CENTER); needL.setFont(new Font("monospaced", Font.BOLD, 20)); needL.setSize(200, 250); c.insets = new Insets(0,25,0,25); c.gridwidth = 1; c.gridx = 0; c.gridy = 1; counter(); pane.add(needL, c); JLabel paidL = new JLabel("| ALREADY PAID"); paidL.setHorizontalAlignment(SwingConstants.CENTER); paidL.setFont(new Font("monospaced", Font.BOLD, 20)); paidL.setSize(200,250); c.insets = new Insets(0,25,0,25); c.gridwidth = 1; c.gridx = 1; c.gridy = 1; pane.add(paidL, c); Dimension buttons = new Dimension(); buttons.setSize(winW, (winH/items)); JButton but1 = new JButton("ALFA"); but1.setSize(buttons); c.gridwidth = 1; c.gridx = 0; c.gridy = 2; pane.add(but1, c); JButton but2 = new JButton("BALDWIN EMC"); but2.setSize(buttons); c.gridwidth = 1; c.gridx = 0; c.gridy = 3; pane.add(but2, c); JButton but3 = new JButton("AT&T"); but3.setSize(buttons); c.gridwidth = 1; c.gridx = 0; c.gridy = 4; pane.add(but3, c); JButton but4 = new JButton("DELL 1"); but4.setSize(buttons); c.gridwidth = 1; c.gridx = 0; c.gridy = 5; pane.add(but4, c); } public static void createAndShowGUI(){ Dimension minimumSize = new Dimension(); minimumSize.setSize(winW, winH); JFrame frame = new JFrame("PAGE TITLE"); frame.setMinimumSize(minimumSize); frame.setLocation(0, 0); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addComponentsToPanel(frame.getContentPane()); frame.pack(); frame.setVisible(true); } public static int counter(){ items++; return(items); } public static void main(String[] args){ SwingUtilities.invokeLater(new Runnable(){ public void run(){ createAndShowGUI(); } }); } }
Thanks
- 11-13-2012, 04:27 AM #2
Re: Aligning and Stretching components (i.e. JButton)
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Help with Stretching an Image
By neptune692 in forum Java 2DReplies: 1Last Post: 07-16-2011, 05:04 AM -
Problem with aligning components
By kedecr in forum New To JavaReplies: 2Last Post: 03-09-2011, 01:23 PM -
aligning numbers,..
By rexson98 in forum New To JavaReplies: 6Last Post: 10-09-2008, 01:59 PM -
Having Trouble Aligning JLabels
By Mark_Petrov in forum AWT / SwingReplies: 0Last Post: 01-20-2008, 05:22 PM -
Aligning Labels
By Java Tip in forum Java TipReplies: 0Last Post: 01-02-2008, 06:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks