Posts by Renan Gomes • 19,011 points
435 posts
-
1
votes3
answers228
viewsA: How to get user/visitor name and write it on the screen?
An alternative with Javascript is to use window.sessionStorage or window.localStorage, the explanation for deciding when to use one or the other has already been answered here. DEMO at Jsfiddle…
-
6
votes1
answer106
viewsQ: How to implement a "one to zero" mapping?
The scenario is as follows: A user may have many or no comments in the newsletters posted on a system - obviously, a comment belongs to a single user. The problem is that Hibernate does not have any…
-
3
votes3
answers32528
viewsA: Selected date comparison with current JS date
Although already answered, follows another way using the function isAfter() of Momentjs which is a Javascript library for date handling and manipulation. // 12/05/2015 é depois de 01/05/2015?…
javascriptanswered Renan Gomes 19,011 -
1
votes1
answer577
viewsA: How to find the value of a hashmap element?
No, you have to look for key - which in this case is pergunta. int a = ids.get("pergunta");
-
2
votes1
answer480
viewsA: How to replace <script> tag data with jQuery?
You can assign an identifier to this script tag, so it’s easier to find it, e.g.: <script id='scriptQueSeraAlterado' type='text/javascript'></script> With jQuery: $(function(){ var…
jqueryanswered Renan Gomes 19,011 -
2
votes1
answer2586
viewsA: How to edit the scrollbar in Firefox and Google Chrone
Styling the scrollbar is not a feature specified in CSS, it is not a standard. Still many users and developers request this (and others) Feature be implemented in other browsers through the…
cssanswered Renan Gomes 19,011 -
2
votes1
answer139
viewsA: Turn div into string
Just use Element.outerHTML. Example: var toString = document.getElementById('foo').outerHTML; alert(toString); <div id='foo' class='bar' data-baz='2015'>StackOverflow</div>…
-
2
votes1
answer328
viewsA: Recover String between characters
Considering the call: java MeuPrograma -by<usuario> -<mensagem> You can simply use the parameters sent to the method main: public class ClasseQuePossuiMetodoPrincipal { public static…
-
4
votes2
answers2888
viewsA: How to use mouse click and keyboard ENTER?
Click-through events can be captured through a ActionListener. The pressing of a certain key can be obtained with KeyEventDispatcher next to the KeyboardFocusManager. This answer of utluiz explains…
-
4
votes1
answer2159
viewsQ: How to pass the value of one variable in JSP to another in Javascript?
I’m trying to define the value of a variable within a tag script with JSP expression language. I tried this to check that the value was not empty: <c:if test="${!empty newsletter.id}">…
jspasked Renan Gomes 19,011 -
3
votes1
answer1327
viewsA: text-overflow: Ellipsis - Displaying text when mouse over
If the title is larger than the div where it is, automatically the line will be broken and the rest of the text will go to the bottom line. So what you need, basically is to have a size set in the…
-
8
votes2
answers669
viewsA: How to handle div size without using Hover
You can enter a class responsible for increasing the size of the div when this is clicked, for example, a class that expands the size of the div in 'x' pixels. How you do this depends on the support…
-
2
votes1
answer180
viewsA: Ideal "replacement" for the placeholder
Change your document to HTML5 by simply changing the doctype at the beginning of the file to <!doctype html>. <!doctype html> <html> <!-- head --> <body> <input…
-
9
votes3
answers11380
viewsA: How to copy objects in java
Just overwrite the method Object#clone, but your class needs to implement the interface Cloneable: By convention, the classes implementing this interface must replace Object.clone (which is…
javaanswered Renan Gomes 19,011 -
1
votes2
answers57
viewsA: Center label on a dynamic div
You can do this with Flexbox. var div = document.createElement("div"); div.id = "div"; div.style.width = "300px"; div.style.height = "300px"; div.style.border = "1px solid #000";…
javascriptanswered Renan Gomes 19,011 -
1
votes2
answers1857
viewsA: For in a Java Object Arraylist
In fact the exception thrown is a IndexOutOfBoundsException when you try to access the indexes with the value of the variables i and j on the second to last line: System.out.println(…
-
2
votes3
answers448
viewsA: Call a preloader before sending contact
You can create a block in your HTML document containing the content that will be shown at the time of the request. For example: // foo.css .imagem-carregando { visibility: hidden } // foo.html…
jqueryanswered Renan Gomes 19,011 -
3
votes1
answer2606
viewsA: Change the color of a jProgressBar
These properties need to be defined before creating the JProgressBar. For example: UIManager.put("ProgressBar.background", Color.orange); UIManager.put("ProgressBar.foreground", Color.blue);…
-
5
votes3
answers10234
viewsA: border-Radius in table does not work CSS
Just apply on the table. table { border: 2px solid #ccc; border-radius: 5px; } <table> <tr> <td>foo</td> <td>foo</td> <td>foo</td> </tr>…
-
2
votes1
answer312
viewsA: Animation with height with relative measurements
There are simpler and easier ways to create the behavior you are looking for. By far, opting for the element’s change of position is the more suicidal¹ worst. Change the rule to position:relative…
-
1
votes1
answer396
viewsA: Pseudo file upload with Javascript
If your question is only how to turn a file into Base64: Use the function FileReader#readAsDataURL to read the file. After reading, you can use FileReader#result to obtain the result. see browsers…
javascriptanswered Renan Gomes 19,011 -
3
votes1
answer343
viewsA: How to get a resource that is in the same class package that will use it?
I managed to solve the problems, but I made some changes in the structure of the project. src |- java | | | |- br.foo.settings | |- Settings.java |- resources |- settings.json I’m getting the file…
javaanswered Renan Gomes 19,011 -
6
votes2
answers3174
viewsA: Limit Input to a range of values
No need for Javascript: <form action='#'> <input type='number' value='20' min='1' max='4'/> <button type='submit'>Enviar</button> </form>…
-
1
votes5
answers934
viewsA: Alternatives to center the img tag
I believe using the property flex resolve. .wrapper { display: -webkit-flex; display: -ms-flexbox; display: flex; justify-content: center; width: 100%; } <div class='wrapper'> <img…
cssanswered Renan Gomes 19,011 -
5
votes1
answer343
viewsQ: How to get a resource that is in the same class package that will use it?
I created a Java project with the following structure: src |-br.foo.settings | |- settings.json | |- Settings.java | |- ... outros pacotes ... As I am used to the JSON file format, I thought of…
javaasked Renan Gomes 19,011 -
2
votes2
answers19768
viewsA: How to print a page directly, without browser dialog box, using Javascript?
Javascript-only, is not possible. If it were, it would be a major security breach, imagine you visiting any site and suddenly your printer fires by printing multiple sheets without your permission?…
-
6
votes2
answers1331
viewsA: What is the difference between Animation and Transition CSS
One transition is still an animation, however this is more limited. You can set the running time, the delay, which attributes will be affected by the transition... But you cannot define what should…
-
1
votes1
answer204
viewsA: Selective.js does not work
According to Github’s description plugin: Selectize is the Hybrid of a textbox and box. It’s jQuery based and it has autocomplete and Native-feeling Keyboard navigation; Useful for tagging, contact…
javascriptanswered Renan Gomes 19,011 -
0
votes2
answers828
viewsA: Select input text by its value
Can traverse the input[type="text"] checking whether the value of it is "hi". $('input[type="text"]').each(function(e){ if($(this).val() == 'oi'){ // faz algo } }); $(function(){…
-
1
votes1
answer91
viewsA: Enable mobile browsers' zoom feature in dropdown
One way is to create a false element, with the appearance of a dropdpwn / select but actually does nothing, that is, being something only visual. For example: .fake-dropdown { border: 2px solid…
-
2
votes2
answers2689
viewsA: Align text in the vertical center of a circle
An alternative is to work with flexbox. And for one simple reason: You don’t have to worry about the question of vertical and horizontal positioning, the property does all the work based on the…
-
5
votes3
answers37193
viewsA: How to enable and disable fields by clicking button
You can create a function to define the state of the elements, for example: function setDisabled(state){ $('.form-horizontal input,select,textarea').each(function(){ $(this).prop("disabled", state);…
jqueryanswered Renan Gomes 19,011 -
2
votes1
answer446
viewsA: Search on a website
The way you’re doing it you’re getting all the links (from the whole page). If your goal is to get only the recipe link, you need to inspect the HTML code to verify where this information is loaded.…
javaanswered Renan Gomes 19,011 -
2
votes1
answer162
viewsA: Open/Close Disk Player (Vbs)
One of the builders of the class File allows sending as argument the directory where the file should be created. Having this in mind, just pass a String containing the directory path. For example:…
javaanswered Renan Gomes 19,011 -
3
votes2
answers1169
viewsA: Doubt - setDefaultCloseOperation
Not like that. setDefaultCloseOperation receives an integer corresponding to the action that must be taken, for example to close the frame JFrame#EXIT_ON_CLOSE :…
-
11
votes2
answers280
viewsQ: How to implement a library that has features similar to jQuery?
I would like to create a very simple library containing only the functions I most use, following an idea similar to those in jQuery. For example: I created the following function to get an element:…
javascriptasked Renan Gomes 19,011 -
2
votes1
answer128
viewsA: How to position a component next to the Windows clock?
By the method setLocation(int x, int y) of your JFrame. I believe your doubt is actually how to get these two values to then position the component. By means of an object GraphicsDevice you get the…
-
20
votes1
answer261
viewsQ: What is the difference between these two implementations?
I was reading some articles about Patterns and I had a doubt in the following two examples. Suppose I have a single function that returns an element to me through the ID sent as argument. The first:…
javascriptasked Renan Gomes 19,011 -
1
votes2
answers1998
viewsA: How to close a Jframe using keyboard events?
The way you are doing (I believe) the event will never be triggered. I had to create something similar a while ago and needed a AbstractAction to define what should occur when the key Esc were…
-
2
votes2
answers2215
viewsA: Show remaining session time
You can use the method getLastAccessedTime() that returns the time (in milliseconds) of the last session-associated request. And then use the method getMaxInactiveInterval() to obtain the maximum…
-
1
votes1
answer652
viewsA: How to prevent a JSESSIONID from being created when accessing a JSP page?
After several attempts and catch a lot trying to solve, I succeeded. And the solution was to use the session="false" which I quoted in the question and which I had previously tried unsuccessfully.…
-
2
votes2
answers19485
viewsA: Bootstrap dropdown menu not working
Bootstrap has a dependency: jQuery. Just include the library code before including the file bootstrap.js (or bootstrap.min.js). <!doctype html> <link rel='stylesheet'…
twitter-bootstrapanswered Renan Gomes 19,011 -
2
votes1
answer652
viewsQ: How to prevent a JSESSIONID from being created when accessing a JSP page?
I created a simple JSP page, which does nothing but call a Servlet to validate a login. Here is the code of the page index.jsp: <%@page contentType="text/html" pageEncoding="UTF-8" %>…
-
2
votes4
answers784
viewsA: Break an integer into small parts in Java
int value = 12345; ArrayList<Integer> array = new ArrayList<>(); for(char each : Integer.toString(value).toCharArray()) array.add(Integer.parseInt(Character.toString(each))); Example…
javaanswered Renan Gomes 19,011 -
2
votes1
answer201
viewsA: How do I use a mixin created in another file?
You need to reference the file where this is mixin, doing the @import. /* mixin.less */ .title(){ text-decoration: none } /* reset.less */ @import "mixin.less"; .title { .title(); } One way to…
lessanswered Renan Gomes 19,011 -
4
votes2
answers3910
viewsA: Get first digits of a number in Java
At first, you can convert the number to a String and then use the method substring to "cut" from index 0 to the digit numbers that must be returned. For example: public int foo(int number, int…
-
1
votes1
answer181
viewsA: Organize list based on an integer value of its elements
Use the method Collections.sort() passing as argument their ArrayList and an object Comparator<T>. The very Collections provides the Collections.reverseOrder. import java.util.ArrayList;…
-
2
votes1
answer269
viewsA: Script to Calculate By Dropdown without onclick
You can wait for the event of keyup in your field to update the result. This event will be triggered when the key is pressed and released. To make it more automatic, you can wait for the event…
-
1
votes4
answers57975
viewsA: How to clear html form fields?
You would need to use Javascript if you needed to reset a variable or clear a specific field, as proposed in reply from César Souza. If you need to clear all fields, use a input type='reset'. input…
-
4
votes1
answer4920
viewsA: Smooth link anchor scrolling
Just change this snippet of your code: $(this).click(function () { if($(window).width() > 760){ $('html, body').animate({scrollTop: targetOffset}, 300); return false; } }); Example I had to put…