JavaScript: Include/Append objects/buttons inside a <span> - java

I have a really long javascript code which basically has a form and generates buttons.
I want to place the buttons together inside a tag so i could fix up their appearance as a group.
How do I achieve this?
i know i basically have to use "document.createElement ("span")" but i'm kind of stuck there... please help

Do you use JQuery? it has .wrap() method, or when you generates form and buttons, directly wrap the buttons in a 'span', good luck!

Related

Making Java button dynamically?

I am new to Java and I am working on a project where depending on number of files in a directory,
buttons will be created respectively. Each button will have a customized right click context menu.
How can I achieve this or is this feasible?
I just want to know the approach to do this.
The approach that you may try:
While you iterate your directory/file list (or other process that will determine the button creation), you can generate (create an instance of) a new button (JButton), I assume you know how to use new, and put it on your form / panel.
However, most of the time, layout would become an annoying issue here.
Thus, you may try to use MigLayout to handle this.
It will help you a lot in putting your stuffs in a tidy and convenient way.
Try this approach and when you have a specific coding-part question, you can try to search the existing solution in SO (StackOverflow) or if it doesn't exist, you can ask that specific code-related question.
Hope it helps.

GWT-508 compliant- How to set HTML tags

I am in the process of making my GWT page 508 compliant and I need to add some additional information on the sort buttons in my cellTable for the screen reader to pick up. Basically I need to know how to set the Label HTML tag from the cellTable.
I know how to use the setTitle() and setAlt() methods but I can't seem to find an easy way to set the Label for buttons. I understand screen readers can optionally view Title tags but that is not what I want to have to do.
I cant seem to find anyone else out there with this problem, how has this not come up more?
There's a TODO in the code actually: https://gwt.googlesource.com/gwt/+/2.6.0/user/src/com/google/gwt/user/cellview/client/DefaultHeaderOrFooterBuilder.java
// TODO: Figure out aria-label and translation of label text
and there doesn't seem to be any hack/hook to add it.
So the only solution seems to be to fork/patch GWT (and if possible contribute the patch upstream).
BTW, the sort icons are not buttons, just indicators. The whole table header responds to click, so the aria-label has to be added to the <th> element.
(well, actually, there seems to be a workaround: walk the table DOM looking for the appropriate <th> element and add the aria-label attribute using Roles.getButtonRole().setAriaLabelProperty(); but fixing GWT would be less fragile, much better in the long run and good for everyone)

Adding 2 groups of JRadioButton to be corresponding the same

I am doing a simple GUI painting box program.
However, I have a problem with adding 2 similar separated groups to be corresponding in the same way.
I mean when I click the JRadioButtonMenuItem Line, then the JRadioButton Line below also has to be selected too. What should I do?
Do you need to see my code?, please let me know
Thank you so much.
P/s: it says I need 10 reputation to post image
Share the model between the two radio buttons:
JRadioButton radioButton = new JRadioButton("Line");
JRadioButtonMenuItem radioMenuItem = new JRadioButtonMenuItem("Line");
radioMenuItem.setModel( radioButton.getModel() );
Actually, you should share the Action as well between the two components. Read the section from the Swing tutorial on How to Use Actions for more information and examples.
The exact solution depends a lot on how your code is structured right now. I bet that the standard library has some functionality to accomplish what you want to do, but if you want to go ahead and implement it then you might as well (minimal time input and you learn something).
The most direct solution that comes to my mind is to encapsulate selecting a button in a method that will manipulate all sets of corresponding buttons. I am going to assume that you are using action listeners for the buttons right now, if not you could adapt the idea. In the action listener, you can detect the mouse click and perform some work as necessary. That work should include updating the other buttons appropriately too. You could even create a method that both action listeners call and updates all necessary sets of buttons.
It is also possible to use the same action listener on both sets of the buttons, but you'll need to know which selection the user wants to be active (likely an easy task).
My Java is pretty rusty, so I am not including any example code, but if anything is unclear or you think an example would help I can do so.
Hope at least something here helps you. Good luck!

Adding a Basic Java Program into Website

Firstly I am no longer a student and doing this for other purposes, so don't hold back on the help ;)
I want to incorporate a simple program into my webpage. I want 4 buttons labelled right arm, left arm, activate voice and walk forward. There will be a box above these buttons showing an image of a robot and as the buttons are pressed by the user I want a different image to be loaded in the box.
So if the right arm button is pressed the image with the robot raising its right arm will need to be displayed.
So basically all I want the buttons to do is to load the image that belongs to each one. I am assuming java is the best choice? I have the open source Java package, would I need any other software when it comes to embedding it into a webpage? My webpage is done on dreamweaver and I am pretty good with html. Would appreciate it if someone could point me to the right direction.....Thanks
Don't use Java for this. Use JavaScript. Something like this:
HTML:
<img src="one.jpg" id="firstImage" />
<img src="two.jpg" id="secondImage" />
​<button id="doSomething">Do Something</button>
<button id="doSomethingElse">​Do Something Else</button>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
CSS:
​img {
display: none;
}​
JavaScript:
var hideImages = function() {
$('#firstImage').hide();
$('#secondImage').hide();
};
$('#doSomething').click(function() {
hideImages();
$('#firstImage').show();
});
$('#doSomething').click(function() {
hideImages();
$('#secondImage').show();
});​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
What this essentially does is initially display no images, just buttons. Then as each button is clicked, the corresponding image is displayed. (And all other images are first hidden, since previous button clicks would have displayed previous images.)
This is an overly simple proof of concept, of course. At the very least you'll want to use better variable names :) This just demonstrates the idea of how you'd show/hide images in JavaScript in response to button clicks. (This also assumes the use of jQuery, which is a safe assumption these days. The easiest way to use that is to refer to a CDN link in your page, using a standard HTML script tag.) You can see this code in action here (though the images are broken, of course.)
If there are a lot of buttons and a lot of images, you may be able to re-factor the code to be less repetitive as well. Maybe store the images in an array and have a single button click handler which can associate the sending button with the correct array element, etc. That's up to you.
There are many technologies that could help you: javascript is one of them and it would be much simpler than using Java for such simple thing. You can use Java applet if you really want to use Java for that project.

Adding Focus on SuggestBox?

Hi I want to focus on the SuggestBox as page loads.
I could not find any EventListener for this purpose so I am guessing that I have to
define my own handler to do that (maybe do something with native textbox.focus?)
What is the GWT way to set focus on the text boxes.
Thanks.
I just had to add textBox.setFocus(true).

Categories

Resources