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.EmptyBo
rder;
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(J
Frame.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.addActionListene
r(listener
);
reset.addActionListener(li
stener);
exit.addActionListener(lis
tener);
//Create the radio buttons.
JRadioButton sevenyearButton = new JRadioButton(sevenyearStri
ng);
sevenyearButton.setMnemoni
c(KeyEvent
.VK_B);
sevenyearButton.setActionC
ommand(sev
enyearStri
ng);
sevenyearButton.setSelecte
d(true);
JRadioButton fifteenyearButton = new JRadioButton(fifteenyearSt
ring);
fifteenyearButton.setMnemo
nic(KeyEve
nt.VK_C);
fifteenyearButton.setActio
nCommand(f
ifteenyear
String);
JRadioButton thirtyyearButton = new JRadioButton(thirtyyearStr
ing);
thirtyyearButton.setMnemon
ic(KeyEven
t.VK_D);
thirtyyearButton.setAction
Command(th
irtyyearSt
ring);
//Register a listener for the radio buttons.
sevenyearButton.addActionL
istener(li
stener);
fifteenyearButton.addActio
nListener(
listener);
thirtyyearButton.addAction
Listener(l
istener);
//************
JPanel mainPanel = new JPanel(new BorderLayout());
//buttons calculate reset and add
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,3));
buttonPanel.setBorder( BorderFactory.createEmptyB
order(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.createEmptyB
order(15, 15, 15, 15) );
// Panels to container
textPanel.add(mortAmount);
textPanel.add(userinputmor
tgageamt);
textPanel.add(userinputmor
tgageamt);
textPanel.add(loanTerm);
textPanel.add(userinputter
m);
textPanel.add(Primerate);
textPanel.add(userinputrat
e);
textPanel.add(MonthlyPayme
nt);
textPanel.add(calculatedPa
ymentfield
);
//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.setPreferredScrollab
leViewport
Size(new Dimension(500, 670));
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(sevenyearButton)
;
group.add(fifteenyearButto
n);
group.add(thirtyyearButton
);
//add buttons to radiopanel
radioPanel.add(sevenyearBu
tton);
radioPanel.add(fifteenyear
Button);
radioPanel.add(thirtyyearB
utton);
radioPanel.add(scrollPane)
;
// make payment text box read only
calculatedPaymentfield.set
Editable(f
alse);
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