Java focus question - java

This may be a silly question I don't know.
Is there a way to remove the highlighter to represent focus in a Java GUI?
For example when you click on a button the text will have a slight rectangle around the text.
Thank you

I believe you want to remove the set focusable attribute from your items
using setFocusable(false)
http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html

That feature is there for a reason because it gives user feedback about which component currently has focus. But if you really must turn it off then you can use:
button.setFocusPainted( false );

As far as I knew one of the selling points of swing when it first appeared was that any GUI element could be completely customised. This might help you out: Custom Swing Controls

Related

Alternative for JComboBox without drop down list

Java, Swing, JCombobox.
I need a single-line textbox with 2 arrows (up and down) instead of drop down list.
I'm sure that's pretty easy but i've not been succeeded to find solution.
Thanks in advance.
For your requirement, Java Swing already has a component called JSpinner.
have look at JSpinner with SpinnerListModel
Try using a
JList. Just set the height of the list so that only one element is visible at a time. For further infomation please refer to this...
http://zetcode.com/tutorials/javaswingtutorial/basicswingcomponentsII/

Why is ToolTipManager.sharedInstance.registerComponent(tree) is not done automatically ?

i am new on this site and please correct me if the way i am asking is wrong.
As the question above, why ToolTipManager.sharedInstance.registerComponent(tree) does not done automatically in the Swing? Is it because of performance issues or it is not designed to be used with JTree ?
Tooltips work perfectly well with JTree. In particular, a JTree may have "a different tooltip based on where the mouse is." Registration enables getToolTipText() to "properly display tooltips of its renderers." See How to Use Trees: Customizing a Tree's Display for details.
as the question is "why not": (can only guess of course, wasn't there :) most probably there is no reason, just an oversight. Getting there by comparison with the other collection components (aka: JTable, JList) which do register themselves on init.

Dynamically add Textbox to Window when checkbox is checked

I'm just figuring out my way around SWT. I have a little problem that i cant seem to solve. I have a check-box in my window. When the check-box is checked, i would like add a multi-line, read-only, text box below it, lets say 200x200. I want the height of the window to increase to accommodate this text-box. When the check-box is unchecked I'd like the opposite to happen.
Could you help me with this? I can't find an example but maybe I'm not using the right keywords. Cheers.
--EDIT
the.duckman'ss answer was very helpful. I've managed to get it working to some extent. I'm adding a multi-line textbox 480px high. How do I automatically resize the window to accommodate the text box? When the user checks the checkbox, the textbox shows up but the height of the window doesn't increase to accommodate the textbox. My code is a little long so I've put it in PasteBin — http://pastebin.com/01RxKeEr
Thanks.
I recommend looking at the SWT Snippets to every beginner - that's probably the best place to go to with SWT questions.
This snippet does exactly what you want.
Edit
Ooops, I ignored the second half of your question, sorry. Simply add this line to your listener:
shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT));

Working in java image

I will explain my question clearly.
I need to zoom in/zoom out the world map.
When I click on the particular country in map, control should redirected to new page with respective the country.
I dont have any idea about this in java. Please explain the steps to acheive the above task.
As the question is quite general, here is a general answer: Zooming often means, that you want to display a certain percentage of somethin, and not the whole, where your size of the displayed will not change.
But in your case it seems more like a "find a mouse click in a polygon" thing. So you have to add a selection/click listener to whatever widgets you use (Swt? swing? ....?) where you change what your program renders.
It sounds like you may be trying to reinvent the wheel. Google etc have already solved this problem rather well. It might be better to incorporate an existing solution into your application. Have a look at GoogleEarth inside Java Swing.

Swing: Programmatically select a text

I have a very simple Swing GUI with just a JTetxtArea. I am trying to programmatically select a part of text using:
textArea.select(startSelection,endSelection);
This work. However as soon as I add some other components to the GUI I do not see selection anymore
frame.getContentPane().add(button);
frame.getContentPane().add(textArea);
textArea.select(startSelection,endSelection);
I suspect that during layouting the gui, some event causes the text to be deselected. Am I right? And could anybody suggest a solution?
My goal is to have a program which displays a text, and allows the user to input start and end selection position, and a selection appears between these two position. Thank you.
Text selection only shows when the text component has focus.
Text components also support "highlighting" by using the getHighlighter().addHighlight() method. In this case the highlighting remains whether the component has focus or not.
If you need more help post your SSCCE that demonstrates the problem.
If what you really want is just a selection, not highlight (which behaves differently), you can use JTextComponent.getCaret().setSelectionVisible(true).

Categories

Resources