I am working on a project for which i am using GWT-Graphics. I have drawing Area containing ellipse and text. When i double click on them a pop-up menu appears and gives an option to enter text. Now when i save this text i want it to appear on this drawing area in the place of the previous text.
I am trying to do this but with no luck. It keeps the old text and on top of that it includes the current text. Is there a way to have only the new text to appear.
Any input will be of great help.
Thank you.
For me this sounds like that you are adding a new Text element instead of using the existing one. I wrote a quick test and it seems to work like you want:
public class GwtTest2 implements EntryPoint {
private Text text;
public void onModuleLoad() {
DrawingArea da = new DrawingArea(400, 400);
RootPanel.get().add(da);
da.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
String newTextValue = Window.prompt("", "");
text.setText(newTextValue);
}
});
Ellipse ellipse = new Ellipse(200, 200, 100, 50);
da.add(ellipse);
text = new Text(150, 200, "Hello world!");
da.add(text);
}
}
Related
I want to implement a PieChart with a SelectionWidget. Upon clicking on a segment within an AndroidPlot PieChart, I would like the selection widget label text to display info about the current selected segment. There is an example to do this for an XYPlot within the AndroidPlot demo but it does not translate over well to the PieChart. Any help would be appreciated. Thank you.
I just posted a solution to a similar question here. It was necessary to add a new method to the PieRenderer class but there's a link to a build of Androidplot containing the necessary changes. It's not a production build but for whatever it's worth, its at least as stable as the current production version of Androidplot. Once you have the new build, you'll be able to do something like this:
// detect segment clicks:
pie.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
PointF click = new PointF(motionEvent.getX(), motionEvent.getY());
if(pie.getPieWidget().containsPoint(click)) {
Segment segment = pie.getRenderer(PieRenderer.class).getContainingSegment(click);
if(segment != null) {
// handle the segment click...for now, just print
// the clicked segment's title to the console:
System.out.println("Clicked Segment: " + segment.getTitle());
}
}
return false;
}
});
Just replace System.out.println(...) with your code to update the SelectionWidget.
While making a program, I noticed a bug with the JOptionPane.showMessageDialog() call. I use a button to create a JTextArea that wraps and then display a dialog containing this text area.
If the text area is too large, however, the dialog does not size itself correctly to the height of the JTextArea. The Dialog cuts off the OK button in this example.
I replicated the bug in the following code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DialogBug {
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final String text = "looooooooooooooooooooooong text looooooooooooooooooooooooooooooooooooooong text";
JButton button = new JButton();
button.setPreferredSize(new Dimension(30, 30));
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
JTextArea area = new JTextArea(text, 0, 50);
area.setEditable(false);
area.setLineWrap(true);
area.setWrapStyleWord(true);
area.append(text);
area.append(text);
area.append(text);
JOptionPane.showMessageDialog(frame, area, "why does it do this", JOptionPane.WARNING_MESSAGE);
}
});
frame.add(button);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
I would post a picture, but I don't have enough reputation...
Is there a way to fix this without having to use a JScrollPane?
Here's a screenshot:
If you run the pack command on the dialog (a function in the Window class) it will resize based on subcomponents. For your case you will have to rewrite without using the showMessageDialog() to get the resize to work (so make the dialog first, add the text, pack, then show it)
Dialog b = new Dialog();
// add stuff
b.pack();
For my test code it worked perfectly to get the dialogs to be the right sizes
Without pack()
With pack()
I'm building a nokia s40 app. I've set this app to be in full screen mode and I notice that when I set this full screen mode, I've lost the native back buttons.
I need to build a back button like the native back button (always on screen, in the bottom right side of the screen). I've tried it with a borderlayout and putting it on the south, but the text from the center container doesn't appears over this...and has transparent background.
If anyone has some sample code, it will be great.
this code simply located a button in the bottom right side of the screen. it's work well.
public void startApp() {
Display.init(this);
Form f = new Form();
//Create a ComponentGroup for all components except backbutton
final ComponentGroup cg = new ComponentGroup();
final Button backButton = new Button("BackButton");
// add this part to your code
f.addOrientationListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Dimension d = new Dimension(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
cg.setPreferredSize(d);
backButton.setX(Display.getInstance().getDisplayWidth() - backButton.getPreferredW());
}
});
//set CoordinateLayout to f
f.setLayout(new CoordinateLayout(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight()));
//Dimension d = new Dimension(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
cg.setPreferredH(Display.getInstance().getDisplayHeight());
cg.setPreferredW(Display.getInstance().getDisplayWidth());
cg.setLayout(new BorderLayout());
cg.addComponent(BorderLayout.NORTH, new Button("NORTH"));
cg.addComponent(BorderLayout.EAST, new Button("ESET"));
cg.addComponent(BorderLayout.WEST, new Button("WEST"));
cg.addComponent(BorderLayout.CENTER, new TextArea("sdsdsd"));
cg.setX(0);
cg.setY(0);
backButton.getStyle().setBgColor(0x2233ff);
backButton.setX(Display.getInstance().getDisplayWidth() - backButton.getPreferredW());
backButton.setY(Display.getInstance().getDisplayHeight() - backButton.getPreferredH() - f.getTitleArea().getLayoutHeight());
f.addComponent(cg);
f.addComponent(backButton);
f.show();
}
you can do like this to any form.
if you want back Button is showed in all forms you can write some OOP programming to do this.
it works well.
This question already has answers here:
Add fixed positioned Combobox inside FlowPane
(2 answers)
Closed 9 years ago.
I have a FlowPane with panels which will be used to display data in front of the user.
![enter image description here][1]
I added also scrollpane when the number of the panels is bigger than the visible area.
I also want to add filter which will sort the panels by type and will display only the appropriate. The red area will hold the ComboBox which will be the filter.
And as you can see the red are pushes down the FlowPane which will make a gap between the top component and the scroll when I make the area transparent.
Is there a way to use the z-index and place the red are in front of the FlowPane? Or some other solution?
This is the result that I would like to get:
![enter image description here][2]
Investigate this example based on your code in previous questions:
public class Demo extends Application {
#Override
public void start(Stage stage) throws Exception {
StackPane stackPane = new StackPane();
stackPane.setAlignment(Pos.TOP_LEFT);
stackPane.getChildren().addAll(infrastructurePane(), getFilterPane());
Scene scene = new Scene(stackPane);
stage.setScene(scene);
stage.show();
}
public Pane getFilterPane() {
ObservableList<String> options =
FXCollections.observableArrayList(
"Option 1", "Option 2", "Option 3");
ComboBox<String> combo = new ComboBox<String>(options);
HBox pane = new HBox();
pane.setPadding(new Insets(20));
pane.setStyle("-fx-background-color: rgba(255,0,85,0.4)");
pane.getChildren().add(combo);
pane.setMaxHeight(40);
// Optional
//pane.setEffect(new DropShadow(15, Color.RED));
return pane;
}
public ScrollPane infrastructurePane() {
final FlowPane flow = new FlowPane();
flow.setPadding(new Insets(5, 5, 5, 5));
flow.setVgap(5);
flow.setHgap(5);
flow.setAlignment(Pos.CENTER);
final ScrollPane scroll = new ScrollPane();
scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); // Horizontal scroll bar
scroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); // Vertical scroll bar
scroll.setFitToHeight(true);
scroll.setFitToWidth(true);
scroll.setContent(flow);
// scroll.viewportBoundsProperty().addListener(new ChangeListener<Bounds>() {
// #Override
// public void changed(ObservableValue<? extends Bounds> ov, Bounds oldBounds, Bounds bounds) {
// flow.setPrefWidth(bounds.getWidth());
// flow.setPrefHeight(bounds.getHeight());
// }
// });
//flow.setPrefWrapLength(170); // preferred width allows for two columns
flow.setStyle("-fx-background-color: yellow;");
for (int i = 0; i < 28; i++) {
flow.getChildren().add(generateRectangle());
}
String cssURL = "/com/dx57dc/css/ButtonsDemo.css";
String css = this.getClass().getResource(cssURL).toExternalForm();
flow.getStylesheets().add(css);
return scroll;
}
public Rectangle generateRectangle() {
final Rectangle rect2 = new Rectangle(10, 10, 10, 10);
rect2.setId("app");
rect2.setArcHeight(8);
rect2.setArcWidth(8);
//rect2.setX(10);
//rect2.setY(160);
rect2.setStrokeWidth(1);
rect2.setStroke(Color.WHITE);
rect2.setWidth(220);
rect2.setHeight(180);
rect2.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
rect2.setFill(Color.ALICEBLUE);
}
});
return rect2;
}
public static void main(String[] args) {
launch(args);
}
}
EDIT:
As per comment, here is the combo without pane. Since there is no pane the mouse events will not be blocked. Replace only this method with above one:
public ComboBox getFilterPane() {
ObservableList<String> options =
FXCollections.observableArrayList(
"Option 1", "Option 2", "Option 3");
ComboBox<String> combo = new ComboBox<String>(options);
combo.setTranslateX(10);
combo.setTranslateY(10);
return combo;
}
if you're using JavaFX 8, you can try a Notification Pane from ControlsFX project
It looks like:
It's pretty unclear to get which behaviour you don't want and which one you want.
This sentence "And as you can see the red are pushes down the FlowPane which will make a gap between the top component and the scroll when I make the area transparent." is particularly hard to understand.
But if you just want to "use the z-index and place the red are in front of the FlowPane?", maybe all you're asking for is just a StackPane ?
StackPane lays out its children in a back-to-front stack.
The z-order of the children is defined by the order of the children
list with the 0th child being the bottom and last child on top. If a
border and/or padding have been set, the children will be layed out
within those insets.
http://docs.oracle.com/javafx/2/api/javafx/scene/layout/StackPane.html
If you want the red area be part of the ScrollPane:
Create a VBox
Add The Red Area Component to VBox
Add the FlowPane to VBox
Set VBox as the ScrollPanes Content
If the Layout with VBox's doenst look statisfying try Borderpane and set the "Red Area" top and your flowpane as center.
Is there a way to use the z-index and place the red are in front of the FlowPane? Or some other solution?
see QuidNovi's answer
I was trying to set ticker on a Label with lwuit 1.5, faced this issue:
if I set label.setRTL(true) and then call
label.startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), true);
ticker just shows first 21 characters of the label's text and ignores the rest.
I've tried:
label.setRTL(false);
label.startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), true);
it shows up OK, the text goes from left to right, but when I set this in a FocusListener (cause ticker should start when the label receive focus and stop after it loosed focus) it just change direction (goes from right to left).
here's what i do:
Label test = new Label();
Container c1 = new Container(new FlowLayout());
test.setText("1234567890ABCDEFGHIJ1234567890");
test.setFocusable(true);
test.setRTL(false);
test.addFocusListener(new FocusListener (){
public void focusGained(Component cmpnt) {
((Label)cmpnt).setRTL(false);
((Label)cmpnt).startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), false);
}
public void focusLost(Component cmpnt) {
((Label)cmpnt).stopTicker();
}
});
c1.addComponent(test);
Look at setLabelFor, it will ticker the label for test when test gains focus. You should probably set RTL globally in the look and feel class.
I found the problem. wrong direction happens because I've implemented focusListener before adding the label to container (c1). so I just did this:
c1.addComponent(test);
test.addFocusListener(new FocusListener (){
public void focusGained(Component cmpnt) {
((Label)cmpnt).setRTL(false);
((Label)cmpnt).startTicker(UIManager.getInstance().getLookAndFeel().getTickerSpeed(), false);
}
public void focusLost(Component cmpnt) {
((Label)cmpnt).stopTicker();
}
});
and it simply worked.
in fact I got the idea from Label class source code (lines 149 ~ 153):
// solves the case of a user starting a ticker before adding the component
// into the container
if(isTickerEnabled() && isTickerRunning() && !isCellRenderer()) {
getComponentForm().registerAnimatedInternal(this);
}
this part does not work, but I don't know why. just hope someone fix this bug.