Basic for Java (B4J)
B4J is a 100% free development tool that generates desktop, server and web applications. The compiled apps can run on Windows, Mac, Linux and ARM boards (such as Raspberry Pi). One huge benefit of the applications you create with B4J is that your applications can run on Android and iOS devices too.
- B4J Home Forums
- Documentation: Docs Doc Index Core
- Tutorials: JavaFX Scene Builder Tabpane VB6 to B4J
jFX jFX Colors
JStringFunctions: Docs DL
- How Tos
- Create .Exe
- Download Java 7 JDK.
- Download JavaFX Scene Builder 2.0.
- Download B4J Full Version.
- Download the latest jdbc driver (ojdbc7.jar).
- Create folder for your apps (C:\app\b4j).
- Create folder for library files (C:\app\b4j\libs).
1. Run installers for Java JDK v7 and JavaFX Scene Builder 2.0.
2. Install and configure B4J.
- Run B4J.exe installer.
- Use default destination location.
- Select Install
- Set java path in B4J.
- Once installed launch B4J.
- Tools -> Paths Configuration -> Set path to javac.exe
Test to ensure everything thus far is configured OK.
- Create a path for a test app.
- B4J loads with a minimal app. Press the blue Run button and save project to new folder.
- Program will compile.
- Once done it launches an application with a generic window.
Configure and Test Oracle
- Copy the jdbc driver (ojdbc7.jar) to your library folder (C:\app\b4j\libs).
- Set additional libraries folder in B4J. Tools -> Paths Configuration -> Additional libraries: C:\app\b4j\libs
- Create small test app and folder (C:\app\b4j\oratest).
- On the Libs tab (bottom-right) enable: [x] jSQL
Source Code for oratest:
#Region Project Attributes #MainFormWidth: 600 #MainFormHeight: 400 #AdditionalJar: ojdbc7.jar End Region Sub Process_Globals Private fx As JFX Private MainForm As Form Dim conn As SQL End Sub Sub AppStart (Form1 As Form, Args() As String) MainForm = Form1 conn.InitializeAsync("conn", "oracle.jdbc.driver.OracleDriver", _ "jdbc:oracle:thin:@//localhost:1521/MyDB","SCOTT","tiger") MainForm.Show End Sub Sub conn_Ready (Success As Boolean) If Success = False Then Log(LastException) Return End If Dim rs As ResultSet = conn.ExecQuery("SELECT sysdate FROM dual") Do While rs.NextRow Log(rs.GetString2(0)) Loop rs.Close End Sub
Scene Builder Essentials
The terms Form and AnchorPane are synonymous for these instructions.
Stretch Control to Fill Entire Form (TabPane example)
- Set Form starting width.
- Select the Form image.
- From right menu select Layout.
- Pref Width (ex: 800)
- Pref Height (ex: 400)
- Select TabPane (click the top of control to select entire control)
- From right menu select Layout.
- For the Anchor Pane Constraints set the left, top, bottom and right to 0 (zero).
Control resizes to Form when they are all zero.
Form Resize and Controls
Anchor Pane Constraints can be used to keep a controls relative position on a form.
For instance for a button to stay in the same spot on the top-right of a form simply
set the corresponding properties (top and right).
For a TableView it will require some code too for the cells to resize proportionally.
Sub TableView1_Resize (Width As Double, Height As Double) 'For this code to the cells resizeable from the layout set 'the AnchorPane Constraints (Top, Right, Bottom, Left). For i = 0 To TableView1.ColumnsCount - 1 TableView1.SetColumnWidth(i, (Width - 10dip)/ TableView1.ColumnsCount) Next End Sub
- Setting Background Color of Tabs (Ex: to #eeeeee)
- Drag a TabPane to your form (or Double-Click on TabPane).
- Select Tab.
- Select tab body (properties changes accordingly).
- Left-click the Style text box to bring up list.
- Set Style type value: -fx-background-color
- Enter Style color value: #eeeeee
- Repeat for each tab.