I would like to know the way to span the next node in the second column after the node containing the label "Info" to the rest of the remaining columns and on 3 rows below.
Below is my present output with the associated code.
public class Test extends Application {
#Override
public void start(Stage primaryStage) {
GridPane root = new GridPane();
root.setGridLinesVisible(true);
final int numCols = 5 ;
final int numRows = 12 ;
for (int i = 0; i < numCols; i++) {
ColumnConstraints colConst = new ColumnConstraints();
colConst.setPercentWidth(100.0 / numCols);
root.getColumnConstraints().add(colConst);
}
for (int i = 0; i < numRows; i++) {
RowConstraints rowConst = new RowConstraints();
rowConst.setPercentHeight(100.0 / numRows);
root.getRowConstraints().add(rowConst);
}
Label nameLbl = new Label("Name");
Label nameFld = new Label();
Label infoLbl = new Label("Info : ");
Label infoFld = new Label();
infoFld.setStyle("-fx-background-color: lavender;-fx-font-size: 7pt;-fx-padding: 10 0 0 0;");
Button okBtn = new Button("OK");
Button cancelBtn = new Button("Cancel");
Label commentBar = new Label("Status: Ready");
commentBar.setStyle("-fx-background-color: lavender;-fx-font-size: 7pt;-fx-padding: 10 0 0 0;");
root.add(nameLbl, 0, 0, 1, 1);
root.add(nameFld, 1, 0, 1, 1);
root.add(infoLbl, 0, 1, 1, 1);
root.add(infoFld, 1, 1, 4, 4);
root.add(okBtn, 3, 9, 1, 1);
root.add(cancelBtn, 2, 9, 1, 1);
root.add(commentBar, 0, 11, GridPane.REMAINING, 1);
primaryStage.setScene(new Scene(root, 900, 500));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If you want the label to span four rows, as well as four columns, set its column span as well as its row span to 4:
// root.add(infoFld, 1, 1, 4, 1);
root.add(infoFld, 1, 1, 4, 4);
By default a label will not grow beyond its preferred size (which in this case is zero, because it has no text). Allow it to grow indefinitely:
infoFld.setMaxWidth(Double.MAX_VALUE);
infoFld.setMaxHeight(Double.MAX_VALUE);
I am generating voucher no with the concatenation of jdatechooer and jCombobox, when user selects the jcombobox it creates a voucher no and put it in the jTextField1 and passes focus to jTextField2. Till that the Application works fine. However, after submitting data, after two or three times, when I create a voucher all the JTextFields freezes and I cannot put the data into database. enter code here
public class Voucher extends javax.swing.JInternalFrame {
private java.util.Date Current_Date ;
private java.sql.Date sqlDate;
private Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
private SimpleDateFormat dateformat =new SimpleDateFormat("HH:mm:ss");
private SimpleDateFormat simpleformat =new SimpleDateFormat("yyyy-MM-dd");
private Connection connection;
private PreparedStatement preparedStatement;
private ResultSet resultSet, AccountChartSet;
private DBConnection dbc =null;
private StringTokenizer xToken ;
private String Query, CreatedVoucher, DateVal;
private String firstval,secondVal;
private Integer MaxVoucher , VoucherType, COF;
private Double Balance=0.0;
private Double DEBIT = 0.0 , CREDIT = 0.0;
private int row = 0;
private DefaultTableModel dmodel = new DefaultTableModel(new Object[][]
{
{ null, null, null , null, null },
{ null, null, null , null, null },
{ null, null, null , null, null },
{ null, null, null , null, null }
},new String []
{
"Account Code", "Acct Name", "DR /CR", "Amount"
}){
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
/**
* Creates new form Voucher
*/
public Voucher() {
initComponents();
setTitle("Create Voucher");
dbc = new DBConnection();
connection = dbc.dbcon();
dmodel.setNumRows(0);
Current_Date = new java.util.Date();
jDateChooser1.setDate(Current_Date);
jTextField6.setText(Balance.toString());
FetchCOF();
setVisible(true);
}
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList<>();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jTextField6 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox<>();
jTextField3 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jDateChooser1 = new com.toedter.calendar.JDateChooser();
jComboBox1 = new javax.swing.JComboBox<>();
jTextField1 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel10 = new javax.swing.JLabel();
jList1.setModel(new javax.swing.AbstractListModel<String>() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
jScrollPane2.setViewportView(jList1);
setBackground(new java.awt.Color(69, 105, 159));
setClosable(true);
getContentPane().setLayout(null);
jButton1.setFont(new java.awt.Font("Segoe UI", 0, 12));
jButton1.setIcon(new javax.swing.ImageIcon("D:\\GTradingPK\\src\\gtradingpk\\images\\floppy-disk.png")); // NOI18N
jButton1.setText("Submit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(10, 385, 593, 50);
jTable1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jTable1.setModel(dmodel);
jTable1.setRowHeight(24);
jTable1.setShowGrid(true);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(10, 210, 593, 170);
jTextField6.setEditable(false);
jTextField6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
getContentPane().add(jTextField6);
jTextField6.setBounds(453, 180, 150, 25);
jTextField5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jTextField5.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField5FocusLost(evt);
}
});
getContentPane().add(jTextField5);
jTextField5.setBounds(171, 180, 280, 25);
jTextField4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
getContentPane().add(jTextField4);
jTextField4.setBounds(10, 180, 160, 25);
jLabel7.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("Amount");
getContentPane().add(jLabel7);
jLabel7.setBounds(10, 162, 100, 14);
jLabel8.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 255, 255));
jLabel8.setText("Narration");
getContentPane().add(jLabel8);
jLabel8.setBounds(171, 162, 100, 14);
jLabel9.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel9.setForeground(new java.awt.Color(255, 255, 255));
jLabel9.setText("Balance");
getContentPane().add(jLabel9);
jLabel9.setBounds(453, 162, 100, 14);
jComboBox2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Select", "Debit", "Credit" }));
getContentPane().add(jComboBox2);
jComboBox2.setBounds(453, 130, 150, 25);
jTextField3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
getContentPane().add(jTextField3);
jTextField3.setBounds(171, 130, 280, 25);
jTextField2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField2FocusLost(evt);
}
});
getContentPane().add(jTextField2);
jTextField2.setBounds(10, 130, 160, 25);
jLabel4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("Acct Code");
getContentPane().add(jLabel4);
jLabel4.setBounds(10, 110, 120, 20);
jLabel5.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("Acct Name");
getContentPane().add(jLabel5);
jLabel5.setBounds(171, 110, 120, 20);
jLabel6.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("Debit / Credit");
getContentPane().add(jLabel6);
jLabel6.setBounds(453, 110, 120, 20);
jDateChooser1.setDateFormatString("dd-MM-yyyy");
jDateChooser1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
getContentPane().add(jDateChooser1);
jDateChooser1.setBounds(453, 80, 150, 25);
jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Select Voucher Type", "1-JV", "2-RV", "3-PV", "4-CV" }));
jComboBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox1ItemStateChanged(evt);
}
});
getContentPane().add(jComboBox1);
jComboBox1.setBounds(171, 80, 280, 25);
jTextField1.setEditable(false);
jTextField1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jTextField1.setFocusable(false);
jTextField1.setRequestFocusEnabled(false);
getContentPane().add(jTextField1);
jTextField1.setBounds(10, 80, 160, 25);
jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Voucher Code");
getContentPane().add(jLabel1);
jLabel1.setBounds(10, 64, 120, 14);
jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Voucher Type");
getContentPane().add(jLabel2);
jLabel2.setBounds(171, 64, 120, 14);
jLabel3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Date");
getContentPane().add(jLabel3);
jLabel3.setBounds(453, 64, 120, 14);
jPanel1.setBackground(new java.awt.Color(46, 26, 71));
jPanel1.setLayout(null);
jLabel10.setFont(new java.awt.Font("Segoe UI", 0, 20)); // NOI18N
jLabel10.setForeground(new java.awt.Color(255, 255, 255));
jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel10.setText("CREATE VOUCHER");
jPanel1.add(jLabel10);
jLabel10.setBounds(0, 10, 610, 30);
getContentPane().add(jPanel1);
jPanel1.setBounds(0, 0, 620, 60);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Voucher No is Missing ....");
}
else if (jComboBox1.getSelectedIndex() == 0)
{
JOptionPane.showMessageDialog(null, "Voucher Type is Missing ....");
jComboBox1.grabFocus();
}
else if(jTextField5.getText().equalsIgnoreCase(""))
{
JOptionPane.showMessageDialog(null, "Narration is Missing ....");
jTextField5.grabFocus();
}
else if (Balance != 0 )
{
JOptionPane.showMessageDialog(null, "Debit / Credit is not Equal");
}
else
{
double damount = 0.0 , camount = 0.0, balanceamt = 0.0;
try
{
CreateValues();
Current_Date = jDateChooser1.getDate();
String datestamp = simpleformat.format(Current_Date.getTime());
String timeStamp = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
String DateTimess = datestamp+" "+timeStamp;
xToken = new StringTokenizer(jComboBox1.getSelectedItem().toString(), "-");
String voutype = xToken.nextToken().trim();
Integer voint= Integer.parseInt(voutype);
connection.setAutoCommit(false);
Query = "insert into voucher(voucherno, vdate, cof, decr, naration, debitamount,creditamount, balance, void,statuss, xdate) values(?,?,?,?,?,?,?,?,?,?,?) ";
preparedStatement = connection.prepareStatement(Query);
for(int x = 0 ; x<jTable1.getRowCount(); x++)
{
preparedStatement.setString(1, jTextField1.getText());
preparedStatement.setObject(2,DateTimess);
preparedStatement.setLong(3 , Long.parseLong(jTable1.getValueAt(x, 0).toString()));
preparedStatement.setString(4, jTable1.getValueAt(x , 2).toString());
preparedStatement.setString(5, jTextField5.getText());
if(jTable1.getValueAt(x , 2).toString().equalsIgnoreCase("Debit"))
{
damount = Double.parseDouble( jTable1.getValueAt(x, 3).toString() );
balanceamt = damount - camount;
preparedStatement.setDouble(6, damount);
preparedStatement.setDouble(7, camount);
preparedStatement.setDouble(8, balanceamt);
}
else {
camount = Double.parseDouble( jTable1.getValueAt(x, 3).toString() );
balanceamt = damount - camount;
preparedStatement.setDouble(6, damount);
preparedStatement.setDouble(7, camount);
preparedStatement.setDouble(8, balanceamt);
}
preparedStatement.setInt(9 , voint);
preparedStatement.setString(10 , "u");
preparedStatement.setObject(11, Current_Date);
preparedStatement.addBatch();
damount = 0.0 ;
camount = 0.0;
balanceamt = 0.0;
}
preparedStatement.executeBatch();
Query = "insert into vouchercounter values(?,?,?)";
preparedStatement = connection.prepareStatement(Query);
preparedStatement.setInt(1 , MaxVoucher);
preparedStatement.setObject(2 , Current_Date );
preparedStatement.setString(3, jTextField1.getText());
preparedStatement.execute();
connection.commit();
//System.out.println(resultSet.isClosed());
JOptionPane.showMessageDialog(null, "Voucher Saved Sccessfully....");
MaxVoucher++;
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
//jTextField2.requestFocus();
jComboBox1.setSelectedIndex(0);
jComboBox2.setSelectedIndex(0);
dmodel.setNumRows(0);
row=0;
}catch(SQLException sskl){System.out.println(sskl.getMessage());}
} // else closes
// TODO add your handling code here:
}
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount() == 2 && !evt.isConsumed())
{
evt.consume();
dmodel.removeRow(jTable1.getSelectedRow());
row--;
}
// TODO add your handling code here:
}
private void jTextField5FocusLost(java.awt.event.FocusEvent evt) {
if(jTextField2.getText().equals(""))
{
jTextField2.requestFocus();
}
else if (jTextField3.getText().equals(""))
{
jTextField3.requestFocus();
}
else if (jTextField4.getText().equals(""))
{
jTextField4.requestFocus();
}
else if (jTextField5.getText().equals(""))
{
jTextField5.requestFocus();
}
else if (jComboBox2.getSelectedIndex() == 0)
{
JOptionPane.showMessageDialog(null, "Please Select Debit / Credit");
jComboBox2.requestFocus();
}
else
{
dmodel.addRow(new Object[]{"","","",""});
jTable1.setValueAt(jTextField2.getText(), row, 0);
jTable1.setValueAt(jTextField3.getText(), row, 1);
jTable1.setValueAt(jComboBox2.getSelectedItem().toString(), row, 2);
jTable1.setValueAt(jTextField4.getText(), row, 3);
CalculateValues();
jComboBox2.setSelectedIndex(0);
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField2.grabFocus();
row++;
}
// TODO add your handling code here:
}
private void jTextField2FocusLost(java.awt.event.FocusEvent evt) {
boolean cofound = false;
if( jTextField2.getText().length() >= 4)
{
COF = Integer.parseInt(jTextField2.getText());
try{
AccountChartSet.beforeFirst();
while(AccountChartSet.next())
{
if (COF == AccountChartSet.getInt(1))
{
jTextField3.setText(AccountChartSet.getString(2));
cofound = true;
break;
}
}
if( (COF < 1100) || (COF > 9999))
{
// System.out.println("I am here");
JOptionPane.showMessageDialog(jTextField2, "Invalid Chart of Acctount");
jTextField2.requestFocus();
}
}catch(Exception zsdf){ System.out.println(zsdf.getMessage());}
}
// TODO add your handling code here:
}
private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
/* if(evt.getStateChange() == ItemEvent.SELECTED && jComboBox1.getSelectedIndex() > 0 )
{
CreateValues();
}
*/
CreateValues();
// TODO add your handling code here:
}
void CalculateValues()
{
Balance=0.0;
CREDIT =0.0;
DEBIT = 0.0;
if(jTable1.getRowCount() > 0)
{
for (int x = 0 ; x<jTable1.getRowCount(); x++)
{
if(jTable1.getValueAt(x, 2).toString().equals("Debit"))
{
DEBIT = DEBIT + Double.parseDouble(jTable1.getValueAt(x, 3).toString()) ;
}
else //(jTable1.getValueAt(x, 2).toString().equals("Crdit"))
{
CREDIT = CREDIT + Double.parseDouble(jTable1.getValueAt(x, 3).toString()) ;
}
}
Balance = DEBIT- CREDIT;
jTextField6.setText(Balance.toString());
} // outer if closes
}
void CreateValues()
{
if (jComboBox1.getSelectedIndex()> 0)
{
Current_Date = jDateChooser1.getDate();
DateVal = simpleformat.format(Current_Date);
//sqlDate = new java.sql.Date(Current_Date.getTime());
xToken = new StringTokenizer(jComboBox1.getSelectedItem().toString() , "-");
firstval = xToken.nextToken().trim();
secondVal= xToken.nextToken().trim();
CreatedVoucher = secondVal+"-"+DateVal+"-"+MaxVoucher.toString();
jTextField1.setText(CreatedVoucher);
}
}
void FetchCOF()
{
try{
Query = "select cof, cofname from accountchart ";
preparedStatement = connection.prepareStatement(Query, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
AccountChartSet = preparedStatement.executeQuery();
Query = "select count(vcounter) from vouchercounter ";
preparedStatement = connection.prepareStatement(Query, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
resultSet = preparedStatement.executeQuery();
resultSet.next();
MaxVoucher = resultSet.getInt(1);
MaxVoucher++;
// jTextField2.requestFocus();
}catch(SQLException sdfsda){}
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JComboBox<String> jComboBox2;
private com.toedter.calendar.JDateChooser jDateChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JList<String> jList1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
// End of variables declaration
}
I am trying to place the "Registration form" text at the top but when I do pane.add it separates the spacing between the labels and textfield boxes. How do I add it to the top without it affecting everything below it?
public class RegistrationForm extends Application {
public void start(Stage primaryStage) {
GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
pane.setHgap(5.5);
pane.setVgap(5.5);
Text text = new Text ("Registration Form");
text.setFont(Font.font("Times New Roman", FontWeight.BOLD,
FontPosture.ITALIC, 20));
pane.getChildren().add(text);
pane.add(new Label("User Name: "), 0, 1);
pane.add(new TextField(), 1, 1);
pane.add(new Label("Password: "), 0, 2);
pane.add(new TextField(), 1, 2);
pane.add(new Label("Email: "), 0, 3);
pane.add(new TextField(), 1, 3);
pane.add(new Label("Phone: "), 0, 4);
pane.add(new TextField(), 1, 4);
Button btReg = new Button("Register");
pane.add(btReg, 0, 5);
GridPane.setHalignment(btReg, HPos.LEFT);
Button btCan = new Button("Cancel");
pane.add(btCan, 1, 5);
GridPane.setHalignment(btCan, HPos.LEFT);
Scene scene = new Scene(pane);
primaryStage.setTitle("Registration Form");
primaryStage.setScene(scene);
primaryStage.show();
}
}
In the Docs
add(Node child, int columnIndex, int rowIndex, int colspan, int
rowspan) Adds a child to the gridpane at the specified column,row
position and spans.
You should use:
pane.add(label, 0, 0, 2, 1);
I am attempting to make a loan calculator that shows payment number, interest, principal, and balance in tableview in JavaFX. Right now only the principal and balance columns are populating. I am fairly new to JavaFX, so I am not sure if I have made a mistake in FX or in my formula. Here is my code:
public class LoanTable extends Application {
Integer payment;
Double interest;
Double principal;
Double balance;
#Override
public void start(Stage primaryStage) {
BorderPane border = new BorderPane();
GridPane grid = new GridPane();
ScrollPane scroll = new ScrollPane();
Label labelTitle = new Label("Enter Loan Amount, Number of Years, and Annual Interest Rate");
labelTitle.getStyleClass().add("labelTitle");
Label loan = new Label("Loan Amount");
TextField loanAmount = new TextField();
Label years = new Label("Number of Years");
TextField numYears = new TextField();
Label interestRate = new Label("Annual Interest Rate");
TextField rate = new TextField();
Button compute = new Button("Display Loan Schedule");
TableView<Finance> table = new TableView<>();
TableColumn paymentColumn = new TableColumn("Payment#");
paymentColumn.setMinWidth(200);
paymentColumn.setCellValueFactory(new PropertyValueFactory<Finance, Integer>("payment"));
TableColumn interestColumn = new TableColumn("Interest");
interestColumn.setMinWidth(200);
interestColumn.setCellValueFactory(new PropertyValueFactory<Finance, Double>("interest"));
TableColumn prinColumn = new TableColumn("Principal");
prinColumn.setMinWidth(200);
prinColumn.setCellValueFactory(new PropertyValueFactory<Finance, Double>("principal"));
TableColumn balColumn = new TableColumn("Balance");
balColumn.setMinWidth(200);
balColumn.setCellValueFactory(new PropertyValueFactory<Finance, Double>("balance"));
table.getColumns().addAll(paymentColumn, interestColumn, prinColumn, balColumn);
grid.add(labelTitle, 0, 0);
grid.add(new Label(), 0, 1);
grid.add(loan, 0, 2);
grid.add(loanAmount, 1, 2);
grid.add(years, 0, 3);
grid.add(numYears, 1, 3);
grid.add(interestRate, 0, 4);
grid.add(rate, 1, 4);
grid.add(compute, 4, 0);
scroll.setContent(table);
border.setTop(grid);
border.setBottom(scroll);
Scene scene = new Scene(border, 800, 800);
scene.getStylesheets().add("loan_table.css");
primaryStage.setScene(scene);
primaryStage.show();
compute.setOnAction((e) -> {
Double loanTotal = Double.parseDouble(loanAmount.getText());
Integer year = Integer.parseInt(numYears.getText());
Double rateInterest = Double.parseDouble(rate.getText());
double monthlyInterest = rateInterest / 1200;
double monthlyPayment = loanTotal * monthlyInterest / (1 - 1 / Math.pow(1 + monthlyInterest, year * 12));
balance = loanTotal;
for(int i = 1; i < year * 12; i++) {
interest = monthlyInterest * balance;
principal = monthlyPayment - interest;
balance = balance - principal;
payment = i + 1;
}
ObservableList<Finance> data = FXCollections.observableArrayList(new Finance(payment, interest, principal, balance));
table.setItems(data);
});
}
public static class Finance {
private final SimpleIntegerProperty payment;
private final SimpleDoubleProperty interest;
private final SimpleDoubleProperty principal;
private final SimpleDoubleProperty balance;
private Finance(int payment, double interest, double principal, double balance) {
this.payment = new SimpleIntegerProperty(payment);
this.interest = new SimpleDoubleProperty(interest);
this.principal = new SimpleDoubleProperty(principal);
this.balance = new SimpleDoubleProperty(balance);
}
public Integer getPayment(int numYears) {
return payment.get();
}
public Double getInterest(double rate) {
return interest.get();
}
public Double getPrincipal() {
return principal.get();
}
public Double getBalance() {
return balance.get();
}
}
public static void main(String[] args) {
launch(args);
}
}
I would like to fit the gridbox accross the whole scene as per attached picture and code below, however i cannot whatever I do!!
I have tried generating empty rows and columns but still does not fill, unless i add a lot.
I would like to specify a number of rows and columns and then let the program divide these equally along the screen, please help
how can I also locate the text inside the table the the right of the cell?
#Override public void start(Stage stage) {
timer.start();
buildData_timer.start();
Group root = new Group();
Scene scene = new Scene(root, 1180, 650);
stage.setScene(scene);
stage.setTitle("Separator Sample");
scene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm());
GridPane Mainpane = new GridPane();
scene.setRoot(Mainpane);
Mainpane.setGridLinesVisible(true);
Mainpane.setId("Mainpane");
GridPane prayertime_pane = new GridPane();
prayertime_pane.setId("prayertime_pane");
prayertime_pane.setGridLinesVisible(true);
prayertime_pane.setPadding(new Insets(20, 20, 20, 20));
prayertime_pane.setVgap(20);
prayertime_pane.setHgap(35);
HBox clock1Box = new HBox();
clock1Box.setSpacing(0);
clock1Box.getChildren().addAll(clock);
HBox fajrBox = new HBox();
fajrBox.setSpacing(0);
fajrBox.setMaxSize(155, 54);
fajrBox.getChildren().addAll(fajr_hourLeft, fajr_hourRight, time_Separator1, fajr_minLeft, fajr_minRight);
prayertime_pane.setConstraints(fajrBox, 0, 1);
prayertime_pane.getChildren().add(fajrBox);
HBox zuhrBox = new HBox();
zuhrBox.setSpacing(0);
zuhrBox.setMaxSize(155, 54);
zuhrBox.getChildren().addAll(zuhr_hourLeft, zuhr_hourRight, time_Separator2, zuhr_minLeft, zuhr_minRight);
prayertime_pane.setConstraints(zuhrBox, 0, 2);
prayertime_pane.getChildren().add(zuhrBox);
HBox asrBox = new HBox();
asrBox.setSpacing(0);
asrBox.setMaxSize(155, 54);
asrBox.getChildren().addAll(asr_hourLeft, asr_hourRight, time_Separator3, asr_minLeft, asr_minRight);
prayertime_pane.setConstraints(asrBox, 0, 3);
prayertime_pane.getChildren().add(asrBox);
HBox maghribBox = new HBox();
maghribBox.setSpacing(0);
maghribBox.setMaxSize(155, 54);
maghribBox.getChildren().addAll(maghrib_hourLeft, maghrib_hourRight, time_Separator4, maghrib_minLeft, maghrib_minRight);
prayertime_pane.setConstraints(maghribBox, 0, 4);
prayertime_pane.getChildren().add(maghribBox);
HBox ishaBox = new HBox();
ishaBox.setSpacing(0);
ishaBox.setMaxSize(155, 54);
ishaBox.getChildren().addAll(isha_hourLeft, isha_hourRight, time_Separator5, isha_minLeft, isha_minRight);
prayertime_pane.setConstraints(ishaBox, 0, 5);
prayertime_pane.getChildren().add(ishaBox);
TextFlow fajrtextFlow = new TextFlow();
Text text1 = new Text("الفجر\n");
text1.setId("prayer-text-arabic");
Text text10 = new Text("Fajr");
text10.setId("prayer-text-english");
fajrtextFlow.getChildren().addAll(text1, text10);
prayertime_pane.setConstraints(fajrtextFlow, 1, 1);
prayertime_pane.getChildren().add(fajrtextFlow);
TextFlow duhrtextFlow = new TextFlow();
Text text2 = new Text("الظهر\n");
text2.setId("prayer-text-arabic");
Text text20 = new Text("Duhr");
text20.setId("prayer-text-english");
duhrtextFlow.getChildren().addAll(text2,text20);
prayertime_pane.setConstraints(duhrtextFlow, 1, 2);
prayertime_pane.getChildren().add(duhrtextFlow);
TextFlow asrFlow = new TextFlow();
Text text3 = new Text("العصر\n");
text3.setId("prayer-text-arabic");
Text text30 = new Text("Asr");
text30.setId("prayer-text-english");
asrFlow.getChildren().addAll(text3,text30);
prayertime_pane.setConstraints(asrFlow, 1, 3);
prayertime_pane.getChildren().add(asrFlow);
TextFlow maghribFlow = new TextFlow();
Text text4 = new Text("المغرب\n");
text4.setId("prayer-text-arabic");
Text text40 = new Text("Maghrib");
text40.setId("prayer-text-english");
maghribFlow.getChildren().addAll(text4,text40);
prayertime_pane.setConstraints(maghribFlow, 1, 4);
prayertime_pane.getChildren().add(maghribFlow);
TextFlow ishaFlow = new TextFlow();
Text text5 = new Text("العشاء\n");
text5.setId("prayer-text-arabic");
Text text50 = new Text("Isha");
text50.setId("prayer-text-english");
ishaFlow.getChildren().addAll(text5,text50);
prayertime_pane.setConstraints(ishaFlow, 1, 5);
prayertime_pane.getChildren().add(ishaFlow);
final Separator sepHor = new Separator();
// sepHor.setAlignment(Pos.CENTER_LEFT);
// sepHor.setOrientation(Orientation.HORIZONTAL);
prayertime_pane.setConstraints(sepHor, 0, 1);
prayertime_pane.setColumnSpan(sepHor, 2);
prayertime_pane.getChildren().add(sepHor);
Mainpane.setConstraints(prayertime_pane, 2, 3);
Mainpane.getChildren().add(prayertime_pane);
Mainpane.setConstraints(clock1Box, 7, 1);
Mainpane.getChildren().add(clock1Box);
stage.show();
// stage.setFullScreen(true);
}
Try
ColumnConstraints c1 = new ColumnConstraints();
c1.setHgrow(Priority.ALWAYS);
ColumnConstraints c2 = new ColumnConstraints();
c2.setHgrow(Priority.NEVER);
Mainpane.getColumnConstraints().addAll(c1, c2);
RowConstraints r1 = new RowConstraints();
r1.setVgrow(Priority.NEVER);
RowConstraints r2 = new RowConstraints();
r2.setVgrow(Priority.ALWAYS);
Mainpane.getRowConstraints().addAll(r1, r2);
For more row/column/cell settings investigate GridPane, RowConstraints and ColumnConstraints.
However I suggest you to use AnchorPane or BorderPane here.