Remove Horizontal Border From Middle Cell With Java JTable - java

How can i remove the middle border of jtable.
From this ..
To This ..
here is my code
Object rowData[][] = { { "", "", "", "", "", "", "" }, //4 empty row
{ "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "" },
{ "", "", "", "", "", "", "" }
};
Object columnNames[] = { "File Type", "Total File", "Size(GB)", " ",
"File Type", "Total File", "Size(GB)" };
JTable table = new JTable(rowData, columnNames);
JScrollPane scrollPane = new JScrollPane(table);

one way t do the smilier thing is to draw 2 tables with spacing between them.
Note there will be a some of work to keep 2 tables in sync as one in case of sorting and deleting.

Related

Karate Framework json response collapse the fields diff order then expected [duplicate]

This question already has an answer here:
Karate - How to use nested for each in karate similar to javascript [duplicate]
(1 answer)
Closed 1 year ago.
Expected Json
{ "Main": [ { "Field1": "", "Field2": "", "Field3": "", "Field4": "", "Field5": "", "Field6": "", "Field7": null, "MainSub1": { "Subhead1": [ { "key": "", "value": "" }, ], "Subhead2": [] },"MainSub2": [ { "Field8": "", "Field9": , "Field10": "", "Field11": "", "Field12": "", "Field13": "", "Field14": "", "Field15": "", "Field16": "", "Field17": , "themeName": , "salutationFlag": "", "subhead3": [ { "key": "", "value": "" }] } ] } ] }
But via Karate Framework
{"Main":[{"Field5":"","MainSub1":{"Subhead1":[{"value":"","key":""}],"Subhead2":[]},"ManiSub2":[{"Subhead3":[{"value":"","key":""}],"Field17":"","Field7":,"Field14":"","Field15":,"Field8":"","Field13":"","Field16":,"Field10":"","Field9":"","Field6":"","Field11":"","Field12":""}],"Field6":"","Field2":"","Field1":"","Field4":"","Field3":"","Field7":}]}
The field order does not matter for JSON.
If you really want you can convert the responseBytes to string and use that, but in my opinion that is a waste of time.
* string response = responseBytes

How do I make this call between the radio and the text for DocuSign

In the code below, I have a RadioGroup, named "Pessoa Politicamente Exposta - Cadastro".
When the person clicks on the radio button with the answer "yes",
a text field must appear. I'm trying to use the attributes of RadioGroup conditionalParentLabel and conditionalParentValue, but it does not work.
How do I make this call between the radio and the text?
private List<RadioGroup> getRadioGroups(String numProposta, String seq_envelope) throws Exception {
List<RadioGroup> radios = new java.util.LinkedList<RadioGroup>();
String RADIO_GROUPS =
"SELECT DISTINCT ear.cd_radio, er.ds_radio " +
" FROM envelope_assinatura_radio ear " +
" left JOIN envelope_radio er on ear.cd_radio = er.cd_radio " +
"WHERE ear.cd_envelope = ? " +
" AND ear.seq_envelope = ? ";
PreparedStatement ps = connection.getConnection().prepareStatement(RADIO_GROUPS);
ps.setString(1, numProposta);
ps.setString(2, seq_envelope);
ResultSet rs = ps.executeQuery();
String RADIO_GROUP_ITEM =
"SELECT tag, ds_valor " +
" FROM envelope_assinatura_radio " +
" WHERE cd_envelope = ? " +
" AND seq_envelope = ? " +
" AND cd_radio = ? ";
PreparedStatement psItem = connection.getConnection().prepareStatement(RADIO_GROUP_ITEM);
while (rs.next()) {
String cd_radio = rs.getString("cd_radio");
String ds_radio = rs.getString("ds_radio");
psItem.setString(1, numProposta);
psItem.setString(2, seq_envelope);
psItem.setString(3, cd_radio);
ResultSet rsItem = psItem.executeQuery();
RadioGroup group = new RadioGroup();
group.setRecipientId(seq_envelope);
group.setGroupName(ds_radio);
Tabs signerTabs = new Tabs();
while (rsItem.next()) {
Radio r = new Radio();
r.setAnchorString(rsItem.getString("tag"));
r.setValue(rsItem.getString("ds_valor"));
//group.conditionalParentLabel("Pessoa Politicamente Exposta - Cadastro");
//group.conditionalParentValue("Sim_1");
group.addRadiosItem(r);
}
if (group.getRadios().size() > 0) {
radios.add(group);
}
}
return radios;
}
private List<Text> getAssinaturaText(String numProposta, String seq_envelope) throws SQLException {
List<Text> docs = new java.util.LinkedList<Text>();
String GET_ASSTINATURA_TEXT =
" SELECT eac.ds_tag " +
" FROM envelope_assinatura_text eac" +
" WHERE eac.cd_envelope = ? " +
" AND eac.seq_envelope = ? ";
PreparedStatement ps = connection.getConnection().prepareStatement(GET_ASSTINATURA_TEXT);
ps.setString(1, numProposta);
ps.setString(2, seq_envelope);
ResultSet op = ps.executeQuery();
if (op.next()) {
Text text = new Text();
text.anchorString(op.getString("ds_tag"));
docs.add(text);
}
return docs;
}
In order for this to work correctly, the properties of conditionalParentLabel and conditionalParentValue of the text tab are the ones that have to be populated with the label of the radio button and the value of the radio button that will be in charge of the conditional logic, the radio button itself does not have to have these fields populated. Below is an example on how these should be defined for envelope creation to achieve this behaviour:
"textTabs": [
{
"tabLabel": "Text",
"conditionalParentLabel": "Radio Group1",
"conditionalParentValue": "Yes",
"isPrefilledTab": false,
"fontSize": "size9",
"underline": false,
"italic": false,
"fontColor": "black",
"bold": false,
"font": "lucidaconsole",
"required": true,
"locked": false,
"concealValueOnDocument": false,
"name": "",
"shared": false,
"requireAll": false,
"requireInitialOnSharedChange": false,
"value": "",
"validationPattern": "",
"validationMessage": "",
"disableAutoSize": false,
"maxLength": 4000,
"width": 84,
"height": 22,
"mergeFieldXml": "",
"recipientId": "64895961",
"pageNumber": 1,
"documentId": "1",
"xPosition": 426,
"yPosition": 116,
"trackingId": "c275",
"trackingid": "c275"
}
],
"radioGroupTabs": [
{
"tabLabel": "Radio Group2",
"conditionalParentLabel": null,
"conditionalParentValue": null,
"isPrefilledTab": false,
"fontSize": "size9",
"underline": false,
"italic": false,
"fontColor": "black",
"bold": false,
"font": "lucidaconsole",
"shared": false,
"name": "",
"tooltip": null,
"recipientId": "1",
"documentId": "1",
"groupName": "Radio Group1",
"width": 0,
"height": 0,
"radios": [
{
"tabLabel": "Radio Group2",
"conditionalParentLabel": null,
"conditionalParentValue": null,
"isPrefilledTab": false,
"fontSize": "size9",
"underline": false,
"italic": false,
"fontColor": "black",
"bold": false,
"font": "lucidaconsole",
"shared": false,
"required": true,
"locked": false,
"name": "",
"selected": false,
"value": "Yes",
"tooltip": null,
"recipientId": "1",
"pageNumber": 1,
"documentId": "1",
"groupName": "Radio Group1",
"xPosition": 342,
"yPosition": 103,
"width": 0,
"height": 0,
"trackingId": "c291",
"trackingid": "c291"
},
{
"tabLabel": "Radio Group2",
"conditionalParentLabel": null,
"conditionalParentValue": null,
"isPrefilledTab": false,
"fontSize": "size9",
"underline": false,
"italic": false,
"fontColor": "black",
"bold": false,
"font": "lucidaconsole",
"shared": false,
"required": true,
"locked": false,
"name": "",
"selected": false,
"value": "No",
"tooltip": null,
"recipientId": "1",
"pageNumber": 1,
"documentId": "1",
"groupName": "Radio Group1",
"xPosition": 342,
"yPosition": 123,
"width": 0,
"height": 0,
"trackingId": "c292",
"trackingid": "c292"
}
]

Iterating an ArrayList in nested for loop causing unexpected result

I want to implement Expandable Recycleview with Title and Some SubQuestions in Android I'm using this Example.
I'm facing such issue on constructing the data for Expandable Adapter.
This is my Response from API
[{
"Label": "Title One",
"Question": "SubQuestion One "
},
{
"Label": "Title One"
"Question": "SubQuestion Two"
},
{
"Label": "Title Two",
"Question": "SubQuestion Three"
},
{
"Label": "Title Two",
"Question": "SubQuestion Four"
},
{
"Label": "Title Two",
"Question": "SubQuestion Five"
}]
I want to separate each Question with Label has Title One and the same as Title Two so I did below thing
Step 1: Creating ArrayList of Labels and removing a repetad item from ArrayList
for (int j = 0; j < temp.size(); j++) {
ProgramDefinitionV1Days data = temp.get(j);
mAllTitlesList.add(data.getLabel());
}
mCompareTitlesList.clear();
mCompareTitlesList = removeDuplicates(mAllTitlesList);
Step 2: Comparing mCompareTitlesList with Original Response and get Questions by Label
for (String label : mCompareTitlesList) {
mQuetionsList.clear();
for (int i = 0; i < temp.size(); i++) {
if (label.equalsIgnoreCase(temp.get(i).getLabel())) {
mQuetionsList.add(new Questions(temp.get(i).getQuestion()));
}
}
Log.e("mQuetionsList", "" + new Gson().toJson(mQuetionsList));
Titles mTitles = new Titles(label, mQuetionsList);
mTitlesList.add(mTitles);
}
But unfortunately, I didn't get the Expected Result form it.
[{"mQuestions":[{"mQuestions":"Question Three"},{"mQuestions":"Question Four"},{"mQuestions":"Question Five"}],"mTitle":"Title One"},{"mQuestions":[{"mQuestions":"Question Three"},{"mQuestions":"Question Four"},{"mQuestions":"Question Five"}],"mTitle":"Title Two"}]
On Every Label has All Last label's Questions
What I Expect
[{"mQuestions":[{"mQuestions":"Question One"},{"mQuestions":"Question Two"}],"mTitle":"Title One"},{"mQuestions":[{"mQuestions":"Question Three"},{"mQuestions":"Question Four"},{"mQuestions":"Question Five"}],"mTitle":"Title Two"}]
Any Suggesions ?

Why does my App crash after i set an array?

I used an array the whole time for my app. But i only set the values after the app was created, with:
public String[][] stunde = new String [6][13];
public String[][] lehrer = new String [6][13];
stunde[1][1]= "SZ";
stunde[2][1]= "Bi";
stunde[3][1]= "";
stunde[4][1]= "DG2";
stunde[5][1]= "";
lehrer[1][1]= "Gt";
lehrer[2][1]= "Pön";
lehrer[3][1]= "";
lehrer[4][1]= "Lc";
lehrer[5][1]= "";
but now i wanted to set these values before, so that i could use them in another method.
Like this:
public String[][] stunde = {
{"SZ", "SZ", "Ku", "Ku", "M", "M", "GeL1", "EL2"},
{"Bi", "Bi", "EL2", "EL2", "Pl", "Pl","DG2","If"},
{"", "", "EL2","EL2", "","","M","Bi"},
{"DG2", "DG2", "","", "GeL1","GeL1","Pl","Ku"},
{"", "", "GeL1","GeL1", "If","If","","SZ","","","Sp","Sp"}
};
But after i tried it like in the second code my app started to crash after i opened it.
Any ideas why?
Your old code used indexes on the top-level array starting at one, not zero. It looks like the rest of your app relies on that numbering as well.
Add a "fake" row and column to fix the problem:
public String[][] stunde = {
/*0*/ {"", "", "", "", "", "", "", "", ""},
/*1*/ {"", "SZ", "SZ", "Ku", "Ku", "M", "M", "GeL1", "EL2"},
/*2*/ {"", "Bi", "Bi", "EL2", "EL2", "Pl", "Pl","DG2","If"},
/*3*/ {"", "", "", "EL2","EL2", "","","M","Bi"},
/*4*/ {"", "DG2", "DG2", "","", "GeL1","GeL1","Pl","Ku"},
/*5*/ {"", "", "", "GeL1","GeL1", "If","If","","SZ","","","Sp","Sp"}
};
Now your row 0 remains unused, and the rest of your app that wants rows 1 through 5 would find the data where it used to be before. Same goes for column numbering.
Note: Once you get this under control and the app no longer crashes, a long-term approach to this would be changing the code that uses the arrays to index 0..4 instead of 1..5.

Removing strings from another string in java

Lets say I have this list of words:
String[] stopWords = new String[]{"i","a","and","about","an","are","as","at","be","by","com","for","from","how","in","is","it","not","of","on","or","that","the","this","to","was","what","when","where","who","will","with","the","www"};
Than I have text
String text = "I would like to do a nice novel about nature AND people"
Is there method that matches the stopWords and removes them while ignoring case; like this somewhere out there?:
String noStopWordsText = remove(text, stopWords);
Result:
" would like do nice novel nature people"
If you know about regex that wold work great but I would really prefer something like commons solution that is bit more performance oriented.
BTW, right now I'm using this commons method which is lacking proper insensitive case handling:
private static final String[] stopWords = new String[]{"i", "a", "and", "about", "an", "are", "as", "at", "be", "by", "com", "for", "from", "how", "in", "is", "it", "not", "of", "on", "or", "that", "the", "this", "to", "was", "what", "when", "where", "who", "will", "with", "the", "www", "I", "A", "AND", "ABOUT", "AN", "ARE", "AS", "AT", "BE", "BY", "COM", "FOR", "FROM", "HOW", "IN", "IS", "IT", "NOT", "OF", "ON", "OR", "THAT", "THE", "THIS", "TO", "WAS", "WHAT", "WHEN", "WHERE", "WHO", "WILL", "WITH", "THE", "WWW"};
private static final String[] blanksForStopWords = new String[]{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
noStopWordsText = StringUtils.replaceEach(text, stopWords, blanksForStopWords);
Create a regular expression with your stop words, make it case insensitive, and then use the matcher's replaceAll method to replace all matches with an empty string
import java.util.regex.*;
Pattern stopWords = Pattern.compile("\\b(?:i|a|and|about|an|are|...)\\b\\s*", Pattern.CASE_INSENSITIVE);
Matcher matcher = stopWords.matcher("I would like to do a nice novel about nature AND people");
String clean = matcher.replaceAll("");
the ... in the pattern is just me being lazy, continue the list of stop words.
Another method is to loop over all the stop words and use String's replaceAll method. The problem with that approach is that replaceAll will compile a new regular expression for each call, so it's not very efficient to use in loops. Also, you can't pass the flag that makes the regular expression case insensitive when you use String's replaceAll.
Edit: I added \b around the pattern to make it match whole words only. I also added \s* to make it glob up any spaces after, that's maybe not necessary.
You can make a reg expression to match all the stop words [for example a , note space here]and end up with
str.replaceAll(regexpression,"");
OR
String[] stopWords = new String[]{" i ", " a ", " and ", " about ", " an ", " are ", " as ", " at ", " be ", " by ", " com ", " for ", " from ", " how ", " in ", " is ", " it ", " not ", " of ", " on ", " or ", " that ", " the ", " this ", " to ", " was ", " what ", " when ", " where ", " who ", " will ", " with ", " the ", " www "};
String text = " I would like to do a nice novel about nature AND people ";
for (String stopword : stopWords) {
text = text.replaceAll("(?i)"+stopword, " ");
}
System.out.println(text);
output:
would like do nice novel nature people
IdeOneDemo
There might be better way.
This is a solution that does not use regular expressions. I think it's inferior to my other answer because it is much longer and less clear, but if performance is really, really important then this is O(n) where n is the length of the text.
Set<String> stopWords = new HashSet<String>();
stopWords.add("a");
stopWords.add("and");
// and so on ...
String sampleText = "I would like to do a nice novel about nature AND people";
StringBuffer clean = new StringBuffer();
int index = 0;
while (index < sampleText.length) {
// the only word delimiter supported is space, if you want other
// delimiters you have to do a series of indexOf calls and see which
// one gives the smallest index, or use regex
int nextIndex = sampleText.indexOf(" ", index);
if (nextIndex == -1) {
nextIndex = sampleText.length - 1;
}
String word = sampleText.substring(index, nextIndex);
if (!stopWords.contains(word.toLowerCase())) {
clean.append(word);
if (nextIndex < sampleText.length) {
// this adds the word delimiter, e.g. the following space
clean.append(sampleText.substring(nextIndex, nextIndex + 1));
}
}
index = nextIndex + 1;
}
System.out.println("Stop words removed: " + clean.toString());
Split text on whilespace. Then loop through the array and keep appending to a StringBuilder only if it is not one of the stop words.

Categories