I am making an application that show the information I entered in a textfield, combo box, etc.. into a text area.
I want to hide the text area when I started up the application and when I press on a button I want to show with the desired information.
I've tried to place <nameOfTextArea>.setVisible(false); in the frame constructor, but it is still visible.
How can I start up the frame without seeing this text area?
Constructor frame:
public StudentInfoFrame() {
initComponents();
textAreaVoorOpslaanInfo.setVisible(false);
}
My button in the frame:
private void uitvoerButtonActionPerformed(java.awt.event.ActionEvent evt) {
try{
..... Variables here .....
textAreaVoorOpslaanInfo.setVisible(true);
textAreaVoorOpslaanInfo.append("Voornaam: \t\t" + voornaam + "\n"
+ "Achternaam: \t\t" + achternaam + "\n"
+ "E-mail adres: \t\t" + email + "\n"
+ "Geboortedatum: \t" + geboortedatum + "\n"
+ "Lengte: \t\t" + lengte + "m\n"
+ "Gewicht: \t\t" + gewicht + "kg\n"
+ "Geslacht: \t\t" + geslacht + "\n"
+ "Vooropleiding(en): \t" + vooropleiding + "\n"
+ "Uitwonend: \t\t" + uitwonend);
} catch (Exception e){
System.out.println(e);
}
}
My question is solved. The jTextArea was invisible, but the jScrollPane was not.
Made the jScrollPane invisible in the constructor and it worked as intended.
Thanks for the help from the people above this post.
Call JComponent#revalidate() on parent component after changing element's visibility.
Call JFrame#setVisible(true) in the end after adding all the components.
Try this one:
textAreaVoorOpslaanInfo.hide();
or this:
textAreaVoorOpslaanInfo.show();
Related
I want to program an item that posts the coordinates of certain ores in the chat.
But now my question is whether I can also put parts of the chat message as a translation or only hardcoded, so that it only outputs what I programmed.
I work with Minecraft fabric for 1.18.2 and the code below is what i have:
private void outputValuableCoordinates(BlockPos blockPos, PlayerEntity player, Block blockBelow) {
player.sendMessage(new LiteralText("Found "
+ blockBelow.asItem().getName().getString()
+ " at " +
"(" + blockPos.getX() + ", " + blockPos.getY() + "," + blockPos.getZ() + ")"), false);
}
And i would make a TranslatableText out of "Found" and "at"
I am a new programmer in javafx.
Using java FX in IDE I want to make a student information application.
I want to print the input data into the text area but it prints out in the console now.
(After clicking display button I want to show all the input data in textarea)
please help me out to solve this problem.
I am attaching my code below for your suggestion..
Main.java
Just place
textArea.setText("Name: " + t1.getText() +"\nAddress: " + t2.getText()
+"\nProvince: " + t3.getText() +"\nCity: " + t4.getText()
+"\nPostal Code: " + t5.getText() +"\nPhone Number: " + t6.getText()
+"\nEmail: " + t7.getText() + "\nCourses: "+comboBox.getItems()
+ "\nActivities: "+c1.getText() + "\n"+c2.getText());
into the action handler.
And remove the imports
import javax.swing.JTextArea;
import java.awt.*;
They are not JavaFX.
You are printing your result into the standard output stream (System.out). I assume you want to display what is printed by:
System.out.println("Name: " + t1.getText() +"\nAddress: " + t2.getText()
+"\nProvince: " + t3.getText() +"\nCity: " + t4.getText()
+"\nPostal Code: " + t5.getText() +"\nPhone Number: " + t6.getText()
+"\nEmail: " + t7.getText() + "\nCourses: "+comboBox.getItems()
+ "\nActivities: "+c1.getText() + "\n"+c2.getText());
Please visit the documentation of the TextArea class. Printing your result into the standard output stream has nothing to do with printing your result in your TextArea. Simply use a normal String that contains your result and set the text of your TextArea accordingly.
I'm building a simple calculator Android app in Java that will receive 2 numbers as inputs and when the user presses one of the 4 action buttons (+, -, *, /) the exercise and it's solution will appear in the bottom of the screen inside a TextView in this format:
{num1} {action} {num2} = {solution}
I tried to declare a string and form the exercise's string in it and in the end I used "setText" to change the TextView but instead of showing the full exercise when I run the app it shows something like "androidx.appcompat.widget.AppCom".
Here is an example for the string I form when the user clicks on the + button:
exerciseStr = etNum1.toString() + " + " + etNum2.toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));
Does anybody know what the issue may be?
You should call getText() befor calling toString():
exerciseStr = etNum1.getText().toString() + " + " + etNum2.getText().toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));
Change it to like this.
exerciseStr = etNum1.getText().toString() + " + " + etNum2.getText().toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));
This question already has answers here:
how to make a specific text on TextView BOLD
(30 answers)
Closed 4 years ago.
How to make certain part of Text to Bold ? In String pars I want this specific part of the text to be in bold "How Stock Market works ?" and the remaining part of the text should remain normal.
public class second extends AppCompatActivity {
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
textView = (TextView)findViewById(R.id.Text1);
String pars = "How Stock Market works ?\n" +
"They are called by the collective names of ‘buyers’ and
‘sellers’.\n" +
"\n" +
"So imagine that there is a ‘tug of war’ situation between the
‘buyers’ and the ‘sellers’. The one who wins this war will control the
price.\n" +
"\n" +
"Case 1] Buyers control the game:\n" +
"\n" +
"For the buyers to control the game, there has to be more
supply. More supply of shares would mean that sellers are desperate to sell
their part and hence this would give the control in the hands of buyers.\n"
+
"\n" +
"This makes the market such an interesting place! After all
predictability is boring and tedious. ";
textView.setText(pars);
textView.setMovementMethod(new ScrollingMovementMethod());
}
}
Use spannable String like below code..
private String string="\"How Stock Market works ?\\n\" +\n" +
" \"They are called by the collective names of ‘buyers’ and \n" +
"‘sellers’.\\n\" +\n" +
" \"\\n\" +\n" +
" \"So imagine that there is a ‘tug of war’ situation between the \n" +
"‘buyers’ and the ‘sellers’. The one who wins this war will control the \n" +
"price.\\n\" +\n" +
" \"\\n\" +\n" +
" \"Case 1] Buyers control the game:\\n\" +\n" +
" \"\\n\" +\n" +
" \"For the buyers to control the game, there has to be more \n" +
"supply. More supply of shares would mean that sellers are desperate to sell \n" +
" their part and hence this would give the control in the hands of buyers.\\n\" \n" +
"+\n" +
"\n" +
" \"\\n\" +\n" +
" \"This makes the market such an interesting place! After all \n" +
"predictability is boring and tedious. ";
private SpannableString spannableString=new SpannableString(string);
spannableString.setSpan(new StyleSpan(Typeface.BOLD), 0, 21, 0);
textView.setText(spannableString);
I need to centre two lines of text in a JLabel. My code is:
lblSolution.setHorizontalAlignment(JLabel.CENTER);
...
lblSolution.setText("<html>" + result.getNearest() + "<br>" + "<br>" + result.getSolutionString() + "</html>");
The problem is, it centres the longer of the two lines, and aligns the shorter at the same x position as the other.
This fixed it:
lblSolution.setText("<html><div style='text-align:center'>" + result.getNearest() + "<br>" + "<br>" + result.getSolutionString() + "</div></html>");