Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
requestFocusInWindow();
Randall Twede
Ranch Hand
Posts: 4716
9
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
maybe i am just stupid. i don't get it. this code works fine
public void actionPerformed(ActionEvent e) { //toolbar events if(e.getSource() == print) { System.out.println("inside print"); } else if(e.getSource() == clear) { file = null; pane.setText(""); menus.htmlSourceMenuItem.setEnabled(false); //disable } else if(e.getSource() == save) { FileHelper.save(file, pane.getText()); } else if(e.getSource() == fontType) { name = (String)fontType.getSelectedItem(); //Action action = new StyledEditorKit.FontFamilyAction(name, name); Action action = new StyledEditorKit.FontFamilyAction(null, name); action.actionPerformed(null); //style = context.addStyle("name", null); //Style nameStyle = context.addStyle("name", null); //nameStyle.addAttribute(StyleConstants.FontFamily, name); //style.addAttribute(StyleConstants.FontFamily, name); //doc.setLogicalStyle(pane.getCaretPosition(), style); } else if(e.getSource() == fontSize) { size = Integer.parseInt((String)fontSize.getSelectedItem()); //Action action = new StyledEditorKit.FontSizeAction(selected, size); Action action = new StyledEditorKit.FontSizeAction(null, size); action.actionPerformed(null); //style = context.addStyle("size", null); //Style sizeStyle = context.addStyle("size", null); //sizeStyle.addAttribute(StyleConstants.FontSize, new Integer(size)); //style.addAttribute(StyleConstants.FontSize, new Integer(size)); //doc.setLogicalStyle(pane.getCaretPosition(), style); } else if(e.getSource() == color) { JDialog dialog = JColorChooser.createDialog(frame, "Color Chooser", true, chooser, new ActionListener() { public void actionPerformed(ActionEvent e) { foreColor = chooser.getColor(); } }, null); dialog.setVisible(true); //Action action = new StyledEditorKit.ForegroundAction(foreColor.toString(), foreColor); Action action = new StyledEditorKit.ForegroundAction(null, foreColor); action.actionPerformed(null); //style = context.addStyle("color", null); //Style colorStyle = context.addStyle("color", null); //colorStyle.addAttribute(StyleConstants.Foreground, foreColor); //style.addAttribute(StyleConstants.Foreground, foreColor); //doc.setLogicalStyle(pane.getCaretPosition(), style); } //menu events else if(e.getSource() == menus.openMenuItem) { try { file = FileHelper.open(); try { URL url = file.toURI().toURL(); pane.setPage(url); StyledDocument styledDoc = pane.getStyledDocument(); if (styledDoc instanceof HTMLDocument) { menus.htmlSourceMenuItem.setEnabled(true); } } catch(MalformedURLException mal) { } } catch (IOException ex) { } } else if(e.getSource() == menus.saveAsMenuItem) { file = FileHelper.saveAs(pane.getText()); } else if(e.getSource() == menus.pageSetupMenuItem) { PageSetupDialog setup = new PageSetupDialog(frame, pane); } /* else if(e.getSource() == menus.findMenuItem) { FindDialog finder = new FindDialog(frame); }*/ else if(e.getSource() == menus.replaceMenuItem) { ReplaceDialog replacer = new ReplaceDialog(frame, pane); } //this section uses the new java7 package java.nio else if(e.getSource() == menus.htmlSourceMenuItem) { pane.setEditorKit(new StyledEditorKit()); StringBuilder text = new StringBuilder(); Path path = null; path = Paths.get(file.toURI()); //if file were null this menu item would be disabled try (BufferedReader reader = Files.newBufferedReader(path, ENCODING)) { String line = reader.readLine(); text.append(line); while ((line = reader.readLine()) != null) { text.append(newline); text.append(line); } pane.setText(text.toString()); } catch(IOException ex) { } menus.htmlSourceMenuItem.setEnabled(false); } else if(e.getSource() == menus.helpMenuItem) { } else if(e.getSource() == menus.aboutMenuItem) { JOptionPane.showMessageDialog(frame, "This program was created by Randall Twede\nJuly 2013", "About", JOptionPane.INFORMATION_MESSAGE); } pane.requestFocusInWindow(); }
the last line sets the focus to the JTextPane
why doesn't my dialog do the same?
public void actionPerformed(ActionEvent e) { if(e.getSource() == ok) { int width = (int)(Float.parseFloat(widthField.getText()) * 100); int height = (int)(Float.parseFloat(heightField.getText()) * 100); pane.setSize(width, height); int left = (int)(Float.parseFloat(widthField.getText()) * 100); int right = (int)(Float.parseFloat(widthField.getText()) * 100); int top = (int)(Float.parseFloat(widthField.getText()) * 100); int bottom = (int)(Float.parseFloat(widthField.getText()) * 100); pane.setMargin(new Insets(top,left,bottom,right)); dispose(); pane.requestFocusInWindow(); //dispose(); } else { //dispose(); pane.requestFocusInWindow(); dispose(); } }
apparently no one seems to know
SCJP
Visit my
download page
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
need help setting Styles
Focus and Style problems
need help with StlyedDocument
inner classes
How to set multiple fonts inJTextArea or JTextPane
More...