I'm writing a JavaFX app and have a menubar with partial transparency. When the user mouses over the menubar, it becomes fully opaque. I'd also like it to be opaque when the user has opened one of the menus. Is this possible somehow? I'm using JavaFX 2 if it matters.
Thanks.
try this..!!
menu.setOnShowing(new EventHandler<Event>() {
#Override
public void handle(Event t)
menubar.setStyle("-fx-background-color:transparent"); //
// or you can use set opacity property
menubar.setOpacity(0.25);
}
});
this event occurs when you show you menu...there also menu hidden propety..you can also use it.
Related
I have started implementing JCEF in a project of mine, and I am initializing the embedded browser in a JInternalFrame inside of a JFrame, alongside a series of form fields on a JPanel next to the JInternalFrame. The browser component doesn't fully initialize until the JFrame actually becomes visible, and I'm finding that my JTextFields are uneditable unless the JFrame loses and regains focus.
Any idea of what could be happening and how to fix it? This only happens when using a JInternalFrame with the JCEF component...
It also happens every time I call loadURL to load a new page in the browser: the JTextFields become uneditable again, until I lose/gain focus in the JFrame.
UPDATE:
I have found a hack which allows the JTextFields to become editable again, but I wouldn't call it a solution because it is not very elegant. I added a load handler to the CefClient instance ( client.addLoadHandler(new CefLoadHandlerAdapter()) ) with an #Ovveride on the onLoadingStateChange method, which in turn gives access to the current browser component. From there I can detect when loading in the browser is complete, and use SwingUtilities to get the Window that the browser component is in. Then I setVisible(false) and setVisible(true) on that Window. I say it's not a solution because every time the browser is done loading the Window disappears and reappears. Even though the JTextFields are editable again, it is quite ugly to see the window flashing. I've tried all kinds of revalidate() and repaint() methods to no avail, unless I didn't call them right...
client.addLoadHandler(new CefLoadHandlerAdapter() {
#Override
public void onLoadingStateChange(CefBrowser browser, boolean isLoading,
boolean canGoBack, boolean canGoForward) {
if (!isLoading) {
//browser_ready = true;
System.out.println("Browser has finished loading!");
SwingUtilities.windowForComponent( browser.getUIComponent() ).setVisible(false);
SwingUtilities.windowForComponent( browser.getUIComponent() ).setVisible(true);
}
}
});
If anyone can suggest a better solution, please do!
I figured out the problem by studying the sample JCEF application a little better. I need to implement a FocusHandler in order to release the embedded browser's hold on keyboard input:
private boolean browserFocus_ = true;
---
jTextField1.addFocusListener(new FocusAdapter() {
#Override
public void focusGained(FocusEvent e) {
if (!browserFocus_) return;
browserFocus_ = false;
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
jTextField1.requestFocus();
}
});
I'm working on Tab Pane on JavaFx, my problem is that i can't handle any KeyEvent inside the tab, such as F5 press or any key on the keyboard, also the function is working on any element inside the Tab like TextField, my goal is to handle any event inside the Tab not elements.
This is my code that i tested it
tab.getContent().addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent event) {
System.out.println("Filtering out event " + event.getCode());
event.consume();
}
});
As far as I understand from another Stack Overflow post, layouts (TabPane in your case) do not respond to KeyEvents. So, the solution suggested and also worked for that post is adding the event filter to the scene. If you don't prefer doing that, set TabPane focusable and try your way again.
first i use JavaSE 1.7 -> The product i develop for is setting this standard. So i can not use the Functions of JavaFX8!
I developed a Custom Menu Item like this:
http://de.share-your-photo.com/7f2f7d74d8
There you can see some triangels! If the triangle shows to the right side i want to get a PopUp on the right hand side next to the Menu Item.
My Problem is that the popup should be dragable and it should not be possible that the PopUp leaves the Main Stage.
Could you please help me with this Problem? What kind of class should i use to develop the PopUp?
Maybe is it possible to make a PopUp Object Draggabel?
I solve the problem, by myself.
I added a container (VBox) to the popup and makes this one draggable!
With every new Koordinate, i set the x&y coordinates to the new position!
container.setOnMouseDragged(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
// TODO Auto-generated method stub
if(dragAct==true){
//DRAG HANDLING
}
}
});
I have developed a custom component consist of a layout and two labels within it. This layout is draggable. The code is similar to this :
DragAndDropWrapper boxWrap= new DragAndDropWrapper(layout);
mainLayout.addComponent(boxWrap);
After that I have a RichTextArea that allows the layout to be dropped in it. With this code.
RichTextArea richText= new RichTextArea;
DragAndDropWrapper dndWrapper = new DragAndDropWrapper(richText);
dndWrapper.setDropHandler(new DropHandler() {
public void drop(DragAndDropEvent event) {
//Do whatever you want when something is dropped
}
//Criterio de aceptacion
public AcceptCriterion getAcceptCriterion() {
return AcceptAll.get();
}
});
The code works fine. But when I drop the layout within the RichTextArea y want to get the Text written in this area and add some text but the method richText.getValue() is not updated unless I change the focus to another component or tab out. I guess there is not being communication with the server side so the value is not updated. Is there any way to force a a focus change when mousedown on the layout? I tried with JavaScript but i dont know how to add a onmousedown="function()" attribute to the layout component. I also tried extending RichTextArea and implementing the MouseListener or something or a TextChangeListener, but nothing works.
Any clue? Thank you.
PS: The component cannot be different from a RichTextArea.
Have you set richText.setImmediate(true); ?
Am designing a Notepad application in java, using AWT. Now, i have created the MenuBar as well as the MenuItems, but the thing i can't get is how do i deactivate specific MenuItem, like if we haven't wrote anything in the TextArea, in the Edit Section the cut and copy option, as well as Undo option remains Deactivate. Is there any method in java to do that stuff? Am doing this Using AWT and not Swing.
Got the answer, after trials and errors and surfing. While in the constructor while initializing them we will keep their initial values as "false". Hence when the texteditor opens there is nothing on the screen. So they will appear disabled and then registering TextArea object with KeyListener will do the job of enabling that menuItems. ;)
constructor()
{
undo=new MenuItem("Undo",new MenuShortcut(90));
edit.add(undo);
un.setEnabled(false);
cut=new MenuItem("Cut",new MenuShortcut(88));
edit.add(cut);
cut.setEnabled(false);
copy=new MenuItem("Copy",new MenuShortcut(67));
edit.add(copy);
copy.setEnabled(false);
paste=new MenuItem("Paste",new MenuShortcut(86));
ed.add(paste);
selectAll=new MenuItem("Select All",new MenuShortcut(65));
ed.add(selectAll);
selectAll.setEnabled(false);
textArea.addKeyListener();
}
public void keyTyped(KeyEvent arg0)
{
if(textArea.getText()!=null)
{
cut.setEnabled(true);
copy.setEnabled(true);
undo.setEnabled(true);
selectAll.setEnabled(true);
find.setEnabled(true);
}
}