Advertisement

01.07.2006 at 06:54PM PST, ID: 21688175
[x]
Attachment Details

Adjusting JButton size

Asked by cm1smith in Java Programming Language

Tags: ,

I have a friend that is also taking a class and is having a problem with the size of his JButtons. All he wants to do is increase the width of the buttons so the lable can fix inside the button and not have "...." in the button. Here is his code:
//
//
//
//HayesMortgageMadness2 is a edited version of Rick Littons code posted at UOPHX
//Class POS 407.
// This code has been modified from using Ricks original MortgageGUI.java File.
// It still utilizes a Mortgage File and a MortgageDriver File
// The Mortgage Driver handles all the events from the HayesMortgageMadness
// Added in Tabs control which the two tabs are Mortgage calculator  and Radio Buttons.
// Program does not take numbers larger than 12 digits so dont waste your time trying.
//The second panel Radio buttons has the radio buttons on it
//





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

import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;



public class HayesMortgageMadness2 extends JFrame
 {

 MortgageDriver listener = new MortgageDriver(this);

//set labels
   JLabel mortAmount = new JLabel("Mortgage Amount:$");
   JLabel loanTerm = new JLabel("Loan Years:");
   JLabel Primerate = new JLabel("Interest Rate(0.00):");
   JLabel MonthlyPayment = new JLabel("Mortgage Monthly Payment:$");
//text fields
   JTextField userinputmortgageamt = new JTextField("",10);
   JTextField userinputterm = new JTextField("",10);
   JTextField userinputrate = new JTextField("",10);
   JTextField calculatedPaymentfield = new JTextField("",10);
   JTextField calculatedPayment = new JTextField ("",10);

//buttons
   public ButtonFrame(){
         super("Button Frame");
         setSize(170,25);
   JButton calculate = new JButton("Calculate");
   JButton reset = new JButton("reset");
   JButton exit = new JButton("Exit");


//strings OR COMMANDS for Radio buttons.
       static String sevenyearString = "7 years at 5.35";
    static String fifteenyearString = "15 years at 5.5";
    static String thirtyyearString = "30 years at 5.75";


//*******************
public HayesMortgageMadness2 (){

      super ("Hayes Mortgage MADness");
      setSize (420,350);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


 init(); //runs intialization subroutine or method to build screen.
}
//***********************


//begining code init method

public void init(){
//listener setups for calculate, reset and exit
  calculate.addActionListener(listener);
  reset.addActionListener(listener);
  exit.addActionListener(listener);



  //Create the radio buttons.
             JRadioButton sevenyearButton = new JRadioButton(sevenyearString);
             sevenyearButton.setMnemonic(KeyEvent.VK_B);
             sevenyearButton.setActionCommand(sevenyearString);
             sevenyearButton.setSelected(true);

             JRadioButton fifteenyearButton = new JRadioButton(fifteenyearString);
             fifteenyearButton.setMnemonic(KeyEvent.VK_C);
             fifteenyearButton.setActionCommand(fifteenyearString);


             JRadioButton thirtyyearButton = new JRadioButton(thirtyyearString);
             thirtyyearButton.setMnemonic(KeyEvent.VK_D);
             thirtyyearButton.setActionCommand(thirtyyearString);



//Register a listener for the radio buttons.

      sevenyearButton.addActionListener(listener);
   fifteenyearButton.addActionListener(listener);
   thirtyyearButton.addActionListener(listener);



//************
JPanel mainPanel = new JPanel(new BorderLayout());

//buttons calculate reset and add
JPanel buttonPanel = new JPanel();

buttonPanel.setLayout(new GridLayout(1,3));
 buttonPanel.setBorder( BorderFactory.createEmptyBorder(5,5,5,5 ) );
         buttonPanel.add(calculate);
         buttonPanel.add(reset);
         buttonPanel.add(exit);

//set first tabs
JTabbedPane Tabs = new JTabbedPane();

JPanel textPanel = new JPanel();

//***************

                textPanel.setLayout(new GridLayout(8,2));
        textPanel.setBorder( BorderFactory.createEmptyBorder(15, 15, 15, 15) );

// Panels to container
     textPanel.add(mortAmount);
      textPanel.add(userinputmortgageamt);
     textPanel.add(userinputmortgageamt);
      textPanel.add(loanTerm);
       textPanel.add(userinputterm);
     textPanel.add(Primerate);
       textPanel.add(userinputrate);
     textPanel.add(MonthlyPayment);
     textPanel.add(calculatedPaymentfield);
     //textPanel.add(calculate);
       //textPanel.add(reset);
     //textPanel.add(exit);
//*************
textPanel.add(buttonPanel, BorderLayout.SOUTH);

Tabs.addTab ("Mortgage calculator", null, textPanel, "first panel");
//end of first tab
//***************
//set second tab JTabbedPane Tab = new JTabbedPane();
//****************
JPanel radioPanel = new JPanel();


//table



//end of second tab



Tabs.addTab ("Radio buttons", null, radioPanel, "Radiobuttons");


//table

String[] columnNames = {"Payment number",
                        "Interest",
                        "Balance due"
                       };

Object[][] data = {
    {"Mary", "Campione",
     "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
     "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
     "Knitting", new Integer(2), new Boolean(false)},

};

JTable table = new JTable(data, columnNames);



        JScrollPane scrollPane = new JScrollPane(table);
            table.setPreferredScrollableViewportSize(new Dimension(500, 670));



//Group the radio buttons.
        ButtonGroup group = new ButtonGroup();
        group.add(sevenyearButton);
        group.add(fifteenyearButton);
        group.add(thirtyyearButton);



//add buttons to radiopanel
          radioPanel.add(sevenyearButton);
          radioPanel.add(fifteenyearButton);
          radioPanel.add(thirtyyearButton);
            radioPanel.add(scrollPane);









         // make payment text box read only
         calculatedPaymentfield.setEditable(false);

          getContentPane().add(Tabs);
         // finally, display the frame
         setVisible(true);
//sets the action events





 }
 public static void main(String[] args) {
        HayesMortgageMadness2 gui = new HayesMortgageMadness2();
  }

}
Start Free Trial
[+][-]01.07.2006 at 06:59PM PST, ID: 15640149

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: size, jbutton
Sign Up Now!
Solution Provided By: objects
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01.07.2006 at 07:11PM PST, ID: 15640186

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32