我试图在JTextArea中附加一个由空格组成的字符串。 代码和逻辑一切都很好,但输出不是我想要的方式。 我得到的输出是这样的,
实际输出
期望的输出
这是处方药,而且0 --- 0 --- 0'字符串与剂量指令有关,我希望看起来像这样,
我的代码是,
medicinename_str = medicinepanel.getComboBox().getEditor().getItem().toString();
strength_str = strength.getText();
if(morning.isSelected()){
timings_str = timings_str + "1-----" ;
}else{
timings_str = timings_str + "0-----" ;
}
if(afternoon.isSelected()){
timings_str = timings_str + "1-----" ;
}else{
timings_str = timings_str + "0-----" ;
}
if(night.isSelected()){
timings_str = timings_str + "1" ;
}else{
timings_str = timings_str + "0" ;
}
quantity_str = quantity.getText();
medicinename_str = "Tab. "+medicinename_str;
int spaces = spacelength - medicinename_str.length();//spacelength is initialized to 40 in the constructor of the JPanel the JTextArea is added in.
System.out.println("spaces ="+spaces);
String spacestring = " ";
for(int i = 1; i<spaces; i++){
spacestring = spacestring + " ";
}
medicinename_str = medicinename_str+spacestring;
MainFrame.getPrescriptionArea().append(medicinename_str);
System.out.println("Medicine strlength "+medicinename_str.length());
MainFrame.getPrescriptionArea().append(timings_str+"\n");
timings_str = "";