How to hide a tab bar at bottom.
I used android:windowSoftInputMode="adjustPan|adjustResize". I do not get the desired result. I also added the event bus and when the focus on the edit text disappears tab bar:
public void showTabBar()
{
mTabHost.getTabWidget().setVisibility(View.VISIBLE);
}
public void hideTabBar()
{
mTabHost.getTabWidget().setVisibility(View.GONE);
}
But, it flickers, too, is not suitable. What else can I do?
(source: cs629227.vk.me)
Related
What I just want is when I clicked the Hamburger then it shows menus list. Now I want when I clicked any menu then my drawerstack and drawser should be hide.
I know how to triggers button likedoClick() but I wanna do know for go through API but didn't successful to find any suitable answer. Could you please share your exprience how I can trigger a Hamburger in javafx.
HamburgerSlideCloseTransition transition = new HamburgerSlideCloseTransition(hamburger);
transition.setRate(-1);
hamburger.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
transition.setRate(transition.getRate() * -1);
transition.play();
borderpane.setRight(drawersStack);
drawersStack.toggle(rightDrawer);
});
thank you!
As I suggested in the comments, you could make all the buttons from the drawers from a custom class and feature the event handling there, e.g.
class drawerButton extends Button{
public drawerButton(){
addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
//open desired pane (pdf, favorites, etc)
//close the drawer
}
}
}
My game has a lot of text onscreen as a debug purpose and I need much more text on screen to help me. Here is an image of the debug text on screen.
When I run the application, this is what appears. However what I would like to happen (for debugging) is for another window to pop up. By window I mean like another libgdx application running alongside the game application. And in this second window I want to have all the debug text lay there so that I can see the game for how it will look while it's running without all the debug junk. Any help is extremely appreciated.
You can have a Window pop up when you want to view debug information. It is draggable, which means you can move it around, and you can make is semi transparent if you want to see through it. The window can pop up upon a double click (for example) on your stage. Your Stage code would look roughly like this:
public class MyStage extends Stage {
private boolean debug = false;
private Window debugWindow = new DebugWindow(); // your customized Window that contains the debug info
public MyStage(...) {
addListener(new ClickListener() {
#Override
public void clicked(InputEvent event, float x, float y) {
if (getTapCount() >= 2) { // i.e., double click
debug = !debug;
}
}
});
}
public void act() {
// ...
if (debug && debugWindow.getStage() != this) {
addActor(debugWindow); // This will add the debug window to your stage, making the debug info visible
}
else if (!debug && debugWindow.getStage() == this) {
debugWindow.remove(); // When you want the debug window out of the way
}
}
}
I have a transparent image on a Button (no text), which is placed on a Composite. Since the Composite is white (created with FormToolkit#createComposite(parent, SWT.NONE)), I'd like the Button background to be the same color. How do I do it?
The Label does the trick, but doesn't have the shadows like Button does when I'm clicking on it..
The background color of a Button is determined by the OS. In fact, the documentation for Control.setBackground() states that:
Note: This operation is a hint and may be overridden by the platform. For example, on Windows the background of a Button cannot be changed.
That said, one possible way to circumvent this is to override the paint event as shown here: Changing org.eclipse.swt.widgets background color in Windows. When I tried this out the results were a bit wonky.
The safest and most consistent approach would be to use a label like in your second image, but have different images to display on various mouse events to emulate how a button behaves.
Those images can emulate the shadow just by adding whatever shape of shadow you want to the image itself. That shadow can also change for each image to give the impression that the button is being pressed or not.
For example, I'm thinking something along the lines of:
public class MyButton {
private final Label buttonLabel;
public MyButton(final Composite parent, final Theme theme) {
buttonLabel = new Label(parent, SWT.NONE);
buttonLabel.setImage(theme.getUpImage());
buttonLabel.addMouseListener(new MouseAdapter() {
#Override
public void mouseDown(final MouseEvent mouseEvent) {
buttonLabel.setImage(theme.getButtonPressedImage());
}
#Override
public void mouseUp(final MouseEvent mouseEvent) {
buttonLabel.setImage(theme.getButtonUpImage());
}
});
buttonLabel.addMouseTrackListener(new MouseTrackAdapter() {
#Override
public void mouseEnter(final MouseEvent mouseEvent) {
buttonLabel.setImage(theme.getButtonHoverImage());
}
#Override
public void mouseExit(final MouseEvent mouseEvent) {
buttonLabel.setImage(theme.getButtonUpImage());
}
});
}
}
Where the Theme just has all of the images already conveniently loaded.
You'll also need to make sure that the parent Composite has the background mode set to force its background color:
parent.setBackgroundMode(SWT.INHERIT_FORCE);
Obviously the drawback to this approach is that you have to handle the mouse click logic yourself (ie. mouseDown isn't really clicked until the mouse is released, so you'll have to handle the state of the button in each listener method).
I have already seen : How to set AUTO-SCROLLING of JTextArea in Java GUI?
blackArea = new JTextArea();
blackArea.setFont(new Font("Tahoma", Font.BOLD, 11));
blackArea.setText("Loggend on Administrator...\n" +date);
blackArea.setForeground(Color.RED);
blackArea.setBackground(Color.BLACK);
DefaultCaret caret = (DefaultCaret)blackArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
blackArea.setCaretPosition(blackArea.getDocument().getLength());
scrollPane.setViewportView(blackArea);
This works well. When update to JTextArea, the scroll moved to bottom automatically so I could see the refresh data. But the problem is, when I click the any space in JTextArea, the auto-scrolling is stopped. No more auto scroll works. How to fix it?
SUPPLEMENT : I added text to blackArea calling GUI.blackArea.append("bla bla bla"); GUI is class name where above code included. Thanks for #hovercraft-full-of-eels
Check out Smart Scrolling. It is an improvement over the other scrolling answer.
It the scrollpane is at the bottom when the append occurs it will continue to keep the scrollpane at the bottom. However, if the user has move the viewport from the bottom then the append will not automatically scroll to the bottom.
You don't show where you are adding or appending text to the JTextArea, and this is critical since the changing of the caret position should occur there.
Edit
You state:
Sorry, I just append text in other class, just calling GUI.blackArea.append("bla bla bla"); Should I use SwingUtilities.invokeLater?
I know you've got a decent answer from Rob Camick, a true Swing guru, but I also have to add that you really shouldn't expose your class's fields that way (and hopefully none of your components are declared static as your code suggests that they may be). Instead expose public methods that allow controlled ability to change the state of your fields. For instance your GUI class could have a public method like so
public void blackAreaAppend(String text) {
blackArea.append(text);
// code here to advance cursor
}
Or if this method is always called off of the EDT:
public void blackAreaAppend(String text) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
blackArea.append(text);
// code here to advance cursor
}
});
}
Or if you're just not sure:
public void blackAreaAppend(String text) {
if (SwingUtilities.isEventDispatchThread()) {
blackArea.append(text);
// code here to advance cursor
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
blackArea.append(text);
// code here to advance cursor
}
});
}
}
I solved this problem. this is the problem of view-point. when I click any space on JTextarea, the location of caret is changed, so view-point is changed too. Following my code, there is no update with view point.
So, I made a method :
public static void addLog(final String log){
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
GUI.blackArea.append(log);
GUI.blackArea.setCaretPosition(GUI.blackArea.getDocument().getLength());
}
});
}
I changed blackArea.append("...") to `addLog("...). and I got out of this problem, However, remember that you can't fix caret positon while updating.
I have a JComboBox component in the panel and ItemListener attached to it. But it gets fired after every up/down keypress (when scrolling though opened popup list). I want to change the selected value after the user accepts selection by pressing for example Enter key.
This is not a case when using mouse. When I move mouse over the combobox's list the highlight follows mouse pointer, but selected item is not changed until I press the mouse button. I would like to have the same behavior for keyboard, i.e. moving highlight via up/down arrow does not change selected item, but pressing Enter does.
I believe you should be able to do:
comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
after you have created your comboBox instance to get this functionality
In Java 8 they have fixed this behaviour, but only trigger if u set one UI property
UIManager.getLookAndFeelDefaults().put("ComboBox.noActionOnKeyNavigation", true);
the JComboBox.isTableCellEditor method works for arrow movement through the list, but does not work for type-ahead supported by the KeySelectionManager. i.e. you still get ActionEvents for every non-navigation key the user types, as the JComboBox interprets those characters for searching though the model to move to (or move close to) the user's intended selection.
this solution has a drawback in that it changes the action command for mouse clicks, which was a OK compromise for me because the the flow of the GUI forces the user to change the focus away from the combo box
I ended up making a special KeyListener, that relys on changing the combo box's default action command from comboBoxChanged to comboBoxMovement. Here's the line of code I need after my combo box is all initialized:
setExplicitSelectionManager(myComboBox);
... and here is the method and its contained class that do all the work:
private void setExplicitSelectionManager(JComboBox comboBox) {
class ExplicitSelectionManager implements KeyListener, FocusListener {
private JComboBox src;
private KeyListener superKeyListener;
ExplicitSelectionManager(JComboBox src) {
this.src = src;
// we like what the default key listener does, but not the action command
// it uses for ActionEvents it fires for plain text type-ahead characters
this.superKeyListener = src.getKeyListeners()[0]; // we only have one
src.removeKeyListener(superKeyListener); // will be replace right away, below
}
#Override
public void keyTyped(KeyEvent e) {
// basic combo box has no code in keyTyped
}
#Override
public void keyPressed(KeyEvent e) {
// in the default JComboBox implementation, the KeySelectionManager is
// called from keyPressed. I'm fine with the implementation of
// the default, but I don't want it firing ActionEvents that will cause
// model updates
src.setActionCommand("comboBoxMovement");
this.superKeyListener.keyPressed(e);
src.setActionCommand("comboBoxChanged");
if (e.getKeyCode() == 10) {
src.setSelectedIndex(src.getSelectedIndex());
}
}
#Override
public void keyReleased(KeyEvent e) {
// basic combo box has no code in keyReleased
}
#Override
public void focusGained(FocusEvent e) {
}
#Override
// this will also give us the event we want, if the user decides to Tab out of
// the combo box, instead of hitting Enter
public void focusLost(FocusEvent e) {
src.setSelectedIndex(src.getSelectedIndex());
}
}
ExplicitSelectionManager newSelectionManager = new ExplicitSelectionManager(comboBox);
comboBox.addKeyListener(newSelectionManager);
comboBox.addFocusListener(newSelectionManager);
}
... and here's the action performed method
private void comboBoxActionPerformed(java.awt.event.ActionEvent evt) {
JComboBox source = (JComboBox) evt.getSource();
// "comboBoxChanged" is the default,
// so any normal JComboBox can also use this action listener
if (evt.getActionCommand().equals("comboBoxChanged")) {
updateModel(source.getName(), (String) source.getSelectedItem());
}
}
Its the expected behavior with the ItemListener. whenever the displayed value changes the event is fired. For your requirement use an ActionListener.