WindowBuilder( SWT ) : テキストファイルを読み込む

WindowBuilder のインストールとプロジェクトの作成は 『Pleiades Eclipse 4.7 Oxygen : SWT(Table) + MySQL の SQL(SELECT) で一覧表示』を参照して下さい。

C# と同時並行で Java を勉強するのならば、WindowBuilder がおすすめです。JavaFX は情報が少なすぎるのでプロになってから使えばいいと思います。Java そのものの学習には、これと AndroidStudio で簡単なスマホアプリを作れば十分です。

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class FormOpenText extends ApplicationWindow {
	private Text text;

	// *********************************
	// コンストラクタ
	// *********************************
	public FormOpenText() {
		super(null);
		createActions();
	}

	// *********************************
	// コントロールの追加
	// ※ Design での変更が反映されます
	// *********************************
	@Override
	protected Control createContents(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);

		// *********************************
		// ボタン
		// *********************************
		Button btnNewButton = new Button(container, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				// *********************************
				// ボタンのイベント
				// *********************************
				MessageBox mb = new MessageBox((Shell) parent, SWT.OK|SWT.CANCEL);
				mb.setText("テキスト");
				mb.setMessage("メッセージ");

				int result = mb.open();
				if (result == SWT.OK ) {

					System.out.println("OK");

					String path = "c:\\User";
					String[] filterExt = { "*.txt;*.csv;*.log", "*.*" };
					String[] filterNames = { "テキストファイル", "全て" };

					FileDialog fd = new FileDialog((Shell) parent,SWT.OPEN);
					fd.setFilterPath(path);
					// https://www.programcreek.com/java-api-examples/?class=org.eclipse.swt.widgets.FileDialog&method=setFilterExtensions
					fd.setFilterExtensions(filterExt);
					fd.setFilterNames(filterNames);

					String target = fd.open();
					if (target != null) {
						try {
							BufferedReader buffer = new BufferedReader(
									new InputStreamReader(
											new FileInputStream(target),
											"SJIS"));

							// 一行ぶんの文字列
							StringBuilder textData = new StringBuilder();
							String line_buffer;

							while ( null != (line_buffer = buffer.readLine() ) ) {
								// メモリルに出力
								textData.append( line_buffer + "\r\n" );
							}

							buffer.close();

							// 画面のテキストエリアにセット
							text.setText(textData.toString());

						} catch (Exception ex) {
							ex.printStackTrace();
						}
					}
				}
				if (result == SWT.CANCEL ) {
					System.out.println("CANCEL");
				}
			}
		});
		btnNewButton.setBounds(10, 10, 75, 25);
		btnNewButton.setText("New Button");

		// *********************************
		// テキストエリア
		// *********************************
		text = new Text(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
		text.setBounds(10, 47, 414, 200);

		return container;
	}

	// *********************************
	// 初期処理
	// *********************************
	private void createActions() {

	}

	// *********************************
	// 開始
	// *********************************
	public static void main(String args[]) {
		try {
			FormOpenText window = new FormOpenText();
			window.setBlockOnOpen(true);
			window.open();
			Display.getCurrent().dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// *********************************
	// アプリケーションウインドウ設定
	// *********************************
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("New Application");
	}

	// *********************************
	// Window サイズの初期設定
	// ********************************
	@Override
	protected Point getInitialSize() {
		return new Point(450, 300);
	}
}