First start a TOR node and get its local proxy URI (outside the scope of monero-java).
// create client connected to monerod with tor config
MoneroRpcConnection monerodConnection = new MoneroRpcConnection("http://kyaklhqp4yyza4fmtbvs6z4lrzr5cljxwa7o2d42sfelfhczsmbwzfad.onion:18081")
.setCredentials("superuser", "abctesting123")
.setProxyUri("<tor proxy uri>");
MoneroDaemonRpc monerod = new MoneroDaemonRpc(monerodConnection);// create client connected to monerod with tor address
MoneroDaemonRpc monerod = new MoneroDaemonRpc("http://kyaklhqp4yyza4fmtbvs6z4lrzr5cljxwa7o2d42sfelfhczsmbwzfad.onion:18081"); // can add username and password
// set tor's proxy uri
monerod.setProxyUri("<tor proxy uri>");// create client connected to your monero-wallet-rpc instance
MoneroWallet walletRpc = new MoneroWalletRpc("http://localhost:38084"); // can add username and password
// open or create a wallet
// ...
// set connection to monerod with tor config
MoneroRpcConnection monerodConnection = new MoneroRpcConnection("http://kyaklhqp4yyza4fmtbvs6z4lrzr5cljxwa7o2d42sfelfhczsmbwzfad.onion:18081")
.setCredentials("superuser", "abctesting123")
.setProxyUri("<tor proxy uri>");
walletRpc.setDaemonConnection(monerodConnection);// option 1: get or create full wallet with tor config
MoneroWallet walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig()
.setPath("sample_wallet_full")
.setPassword("supersecretpassword123")
.setNetworkType(MoneroNetworkType.MAINNET)
.setSeed("hefty value scenic...")
.setRestoreHeight(573936l)
.setServerUri("http://kyaklhqp4yyza4fmtbvs6z4lrzr5cljxwa7o2d42sfelfhczsmbwzfad.onion:18081")
.setServerUsername("superuser")
.setServerPassword("abctesting123")
.setServerProxyUri("<tor proxy uri>"));
// option 2: set connection to monerod with tor config
MoneroRpcConnection monerodConnection = new MoneroRpcConnection("http://kyaklhqp4yyza4fmtbvs6z4lrzr5cljxwa7o2d42sfelfhczsmbwzfad.onion:18081")
.setCredentials("superuser", "abctesting123")
.setProxyUri("<tor proxy uri>");
walletFull.setDaemonConnection(monerodConnection);