How to place a JSlider in the middle of an image?

Hi,
Here is the deal. I have an image inside a JLabel. That JLabel is inside a JPanel, which in turn is encompassed by a JScrollPane. This image represents some curve or a frequency function, lets say for instance a sine curve. What I need to do is have a slider, positioned (just to keep things simple for now) in the middle of that image, not above or below or to the side of an image, but rather directly over it. Thus, blocking a small section of the image from view. So that the user can drag the mouse cursor along the (horizontal) slider and see the different values on that curve. I dont know of any LayoutManager that would allow me to place a JSlider at an arbitrary position on top of a JLabel, besides just using a Null Layout. However, when I use a Null Layout my scroll bars disappear and the JSlider itself just sits there doing nothing, without reacting to any mouse movements, and mroe importantly as soon as the application is resized, the JSlider disappears completely.
Any comments/code snippets would be greatly appreciated.
Thanks,
Val

/* From: Java Tutorial - How To Use Layered Panes
*       LayeredPaneDemo.java
*       http://java.sun.com/docs/books/tutorial/uiswing/
*                                components/layeredpane.html
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
public class valy extends JPanel implements ChangeListener {
  private SineWave sineWave = new SineWave();
  JSlider slider;
  JLayeredPane layeredPane;
  public valy() {
    slider = new JSlider(1, 30, 5);
    slider.setBounds(50,125,300,25);
    slider.addChangeListener(this);
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(400,300));
    layeredPane.setBorder(
      BorderFactory.createTitledBorder("Layered Pane App"));
    layeredPane.add(slider, JLayeredPane.PALETTE_LAYER);
    JPanel panel = new JPanel();
    panel.add(sineWave);
    JScrollPane scrollPane = new JScrollPane(panel);
    int width = layeredPane.getPreferredSize().width;
    int height = layeredPane.getPreferredSize().height;
    scrollPane.setBounds(15, 25, width - 30, height - 40);
    layeredPane.add(scrollPane, JLayeredPane.DEFAULT_LAYER);
    add(layeredPane);
  public void stateChanged(ChangeEvent e) {
    sineWave.setCycles(
      ((JSlider)e.getSource()).getValue());
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    JComponent contentPane = new valy();
    contentPane.setOpaque(true);
    frame.setContentPane(contentPane);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocation(300,200);
    frame.setVisible(true);
/* From: Thinking in Java by Bruce Eckel
  *       3rd edition, Chapter 16
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SineWave extends JLabel {
  private static int SCALEFACTOR = 200;
  private int cycles, points;
  private double[] sines;
  private int[] pts;
  public SineWave() {
    setCycles(5);
    setPreferredSize(new Dimension(400,400));
  public void setCycles(int newCycles) {
    cycles = newCycles;
    points = SCALEFACTOR * cycles * 2;
    sines = new double[points];
    for(int j = 0; j < points; j++) {
      double radians = (Math.PI/SCALEFACTOR) * j;
      sines[j] = Math.sin(radians);
    repaint();
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);   
    int maxWidth = getWidth();
    double hstep = (double)maxWidth/(double)points;
    int maxHeight = getHeight();
    pts = new int[points];
    for(int j = 0; j < points; j++)
      pts[j] =
        (int)(sines[j] * maxHeight/2 * .95 + maxHeight/2);
    g2.setPaint(Color.red);
    for(int j = 1; j < points; j++) {
      int x1 = (int)((j - 1) * hstep);
      int x2 = (int)(j * hstep);
      int y1 = pts[j - 1];
      int y2 = pts[j];
      g2.drawLine(x1, y1, x2, y2);
}

Similar Messages

  • How to place af:table in the middle of radio buttons

    Hi,
    I am on jdev 11.1.2.4.
    I've a requirement to have a form with two radio buttons. RB1 & RB2 and af:table component in the middle of these radio buttons
    something like this.
    RB1
    <af:table>
    RB2   <InputTextItem>
    I've tried placing  the table component in the desired place but it's not allowing it.
    please can you help?
    thanks

    Just setup a small sample
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
      <jsp:directive.page contentType="text/html;charset=UTF-8"/>
      <f:view>
        <af:document id="d1">
          <af:form id="f1">
            <af:panelStretchLayout topHeight="50px" id="psl1">
              <f:facet name="top">
                <af:outputText value="SelectBooleanRadio Test" id="ot1" inlineStyle="font-size:x-large;"/>
              </f:facet>
              <f:facet name="center">
                <af:panelGroupLayout id="pgl1" layout="vertical">
                  <af:selectBooleanRadio text="Group A" id="sbr1" simple="true" group="myGroup" value="#{bindings.selGroup1.inputValue}" autoSubmit="true"/>
                  <af:panelGroupLayout id="pgl2" layout="vertical">
                    <af:inputText label="Label 1" id="it1" disabled="#{!bindings.selGroup1.inputValue}" partialTriggers="sbr1 sbr2"/>
                    <af:outputText value="selGroup = #{bindings.selGroup1.inputValue}" id="ot2" partialTriggers="sbr1 sbr2"/>
                  </af:panelGroupLayout>
                  <af:selectBooleanRadio text="Group B" label="Label 1" id="sbr2" simple="true" group="myGroup" value="#{bindings.selGroup1.inputValue}"
                                         autoSubmit="true"/>
                </af:panelGroupLayout>
                <!-- id="af_one_column_header_stretched"  -->
              </f:facet>
            </af:panelStretchLayout>
          </af:form>
        </af:document>
      </f:view>
    </jsp:root>
    and hte pagedef which holds the variable
    <?xml version="1.0" encoding="UTF-8" ?>
    <pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="11.1.1.64.93" id="SelectBooleanPageDef" Package="de.hahn.blog.vctest11g.view.pageDefs">
      <parameters/>
      <executables>
        <variableIterator id="variables">
          <variable Name="selGroup" Type="java.lang.Boolean"/>
        </variableIterator>
      </executables>
      <bindings>
        <attributeValues IterBinding="variables" id="selGroup1">
          <AttrNames>
            <Item Value="selGroup"/>
          </AttrNames>
        </attributeValues>
      </bindings>
    </pageDefinition>
    Timo

  • How to resize and place a Button in the middle of a Region

    Hi,
    I have a requirement where I have to place a button in the middle of a region. This is the only Region on this page and only one button on this region. I made the region bigger by placing the following code in the Region Footer:
    <div style="height:300px; width:300px;"></div>
    Now the Region is big and in the middle of the page. Now I have to place one button in the middle of this region. I am using HTML Button. I also want to increase the size of the button from the default. Can anyone suggest how to do this ?
    Thanks
    Naresh

    Hi,
    I have a requirement where I have to place a button in the middle of a region. This is the only Region on this page and only one button on this region. I made the region bigger by placing the following code in the Region Footer:
    <div style="height:300px; width:300px;"></div>
    Now the Region is big and in the middle of the page. Now I have to place one button in the middle of this region. I am using HTML Button. I also want to increase the size of the button from the default. Can anyone suggest how to do this ?
    Thanks
    Naresh

  • I just got a white frame in the middle of my images in viewer mode. What is it and how did it get there and how do i get rid of it.

    I just got a white frame in the middle of my images in viewer mode in Aperture 3. What is it and how did it get there and how do i get rid of it?

    Just fishin' ...
    Is by any chance "View→Show focus points" checked?
    Does the frame persist after closing and re-opening Aperture?
    Notice anything else different?
    To post a screen shot, you first take it, them upload it.  To take them, I use and recommend Skitch -- one of the best little apps ever.  But this ability is built into OS X.  Use Grab or Preview (search OS X Help for full directions).  In Preview, use "File→Take screen shot ... →From selection ... ".  Save the file in Preview to your drive.  In the Discussion forum click the "Insert Image" icon (a camera) and select the file you created in Preview.

  • How to place a  logo in the BEX

    Hello All,
    I am new to the BW.Could u pl.explain how to place a logo
    in the BEX.
    Thanks & regards
    NSB

    Hi Suresh,
    Are you asking about BEx Excel based reports, or the web reports..there are different ways to go about it.
    For the excel reports youc an create a workbook template and place the logo along with other custom settings for color, font etc.
    For the web based reports you would have to place the logo in your web template.
    Hope this helps...post back if you need more information.

  • How to place a JPanel at the center of another JPanel?

    Can anyone tell me how to place a JPanel inside another JPanel? The first JPanel consists of three JPanels each consisting of a label&textfield and are placed using BoxLayout. The second JPanel is a big blank screen. So, i would like to put the first JPanel at the center of second JPanel(horizontally & vertically). The problem is that i don't have any other component. So,if i try to use FlowLayout, i am able to put it at the center(horizontally, not vertically) only on the top edge. I tried to use BoxLayout. But, i couldn't(as i don't have any other elements). I tried to create some blank elements. But, they are messing up the elements of my JPanel. Any cluesssssssss??????????

    import java.awt.*;
    import javax.swing.*;
    public class CenteredLayout
        private JPanel getPanel()
            GridBagLayout gridbag = new GridBagLayout();
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            JPanel p = new JPanel(gridbag);
            addComponents(new JLabel("label 1"), new JTextField(8), p, gbc);
            addComponents(new JLabel("label 2"), new JTextField(8), p, gbc);
            addComponents(new JLabel("label 3"), new JTextField(8), p, gbc);
            JPanel panel = new JPanel(gridbag);
            panel.setBackground(Color.pink);
            gbc.anchor = GridBagConstraints.CENTER;
            gbc.insets = new Insets(0,0,0,0);
            panel.add(p, gbc);
            return panel;
        private void addComponents(Component c1, Component c2, Container c,
                                   GridBagConstraints gbc)
            gbc.anchor = GridBagConstraints.EAST;
            gbc.gridwidth = GridBagConstraints.RELATIVE;
            c.add(c1, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            c.add(c2, gbc);
        public static void main(String[] args)
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new CenteredLayout().getPanel());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    }

  • How to invoke a webservice in the middle of a BPM process

    I use BPM studio to create processes.
    In the middle part of the BPM process, it need to invoke a web service (an ADF project deployed to weblogic as a web service). Then, it will wait.
    After the process is finished, it will invoke another web service (an ADF project deployed to weblogic as a web service).
    How to invoke web services in and after the process?
    Thank you.

    Hi,
    Thanks for your reply. I use BPM studio 10.3
    In the Catalogue, there are 3 default components which are Fuego, Java, and Plumtree.
    In the Fuego, there is an item of WebServices. In the Plumtree, there is an item named WebServiceProperty.
    If I create a new Module, I cannot find the option of web service.
    How to invoke a webservice (ADF/Java web service developed in Jdeveloper deploy to weblogic ) ?
    Thanks.

  • How to Start a color in the middle of a cell in the table & end in next cel

    Hai,
    I am developing a project in VB6 and the databse in MsAccess, i prepared the Report in HTML, Based on 2 Fields called Nextti & Duration Field I am coloring the Background of cells in the report table.
    Actually the Color should start and end insdie or outside the cell based on the 2 Field Values.
    Table is populated for 4 Years under that 48 months, therefor 2 row headings. 1 for showing Years in column & other for Months & with Some fields.
    the below is the line i use to change the background of a particular cell. Its done when i populate the data in the HTML Report.
    OutStream.WriteLine ("<td bgcolor=Yellow><P align=center><Font FACE=Tahoma size=1 color=black>" & Format(dtShade, "dd") & "</Font></P></td>")
    Now i am able to shade the Cell by giving its background color to yellow as below code
    but the problem is i am able to change the background of the full cell. But i don't need to change the background of the full cell always. For example if Nextti value is 15/1/2005 & Duration is 30 then the shade should start from the middle of January Cell (because of the date 15th)end in the middle of next cell (February). If the duration is 15 then it should end in the (January) same end of cell. Kindly tell me how can i do this through HTML. I heard Div can be used to solve this issue. I am a beginner so kindly any one give me a appropriate example which will suit to solve this issue.
    thankyou,
    Chock.

    Can you work out what the actual HTML is to do
    "Whatever it was that you wanted to do" ? { I couldn't understand that }
    I.e If you make up a Test table, with Your Text editor can you get a sample output that looks like you want?
    But the problem is i am able to change the background of the full cell. But i don't need to change the background of the full cell always. For example if Nextti value is 15/1/2005 & Duration is 30 then the shade should start from the middle of January Cell (because of the date 15th)end in the middle of next cell (February). If the duration is 15 then it should end in the (January) same end of cell.
    Is this something that can be done in HTML?
    If your question is 'amenable' to HTML, figure out conditions for which you want to Set a certain color....
    If the color in one cell for instance depends on the Next Cell, then you're going to have to buffer the whole Table ROW....
    Set which ones should be RED for instance, then output that ROW in HTML...
    If you are using Java for this, then also be aware that you might need to escape certain characters like use "\\" to get "\"
    You'd also probaly have an easier time, however you are doing this if you used some sort of CSS .......

  • How to insert a page in the middle of the document

    How can I add a page in the middle of a document? There are a lot of images in the document and they tend to shift each time I add text.

    Pages version? Number, please!

  • How Do I Fade Out In The Middle Of A Song?

    I cant find out how to do it on certain parts in the middle of a song I am mixing. Can anyone help?

    You may want to head over to http://labs.adobe.com/ and download the public beta release of Soundbooth CS4. It offers multitrack, volume keyframing, and more tools that are better suited for mixing music than the tools offered in Soundbooth CS3.
    Durin

  • Photoshop: how to put your page in the middle

    i've made my first page of my new website with photoshop cs2
    but i want to see it in the middle when i use IE or firefox
    how can i do that with dreamweaver
    my page
    thanks a lot

    Table height is invalid HTML.
    There is no align center option for an image.
    Your code will give horizontal but not vertical centering. To
    get valid,
    vertical centering, read this -
    http://www.apptools.com/examples/tableheight.php
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Pay Low Books!" <[email protected]> wrote
    in message
    news:f47f99$e9c$[email protected]..
    > Your page contains the photo only. Do you want to make
    the photo in the
    > middle?
    > Here is how to do it in Dreamweaver CS3:
    > Because your page looks like it contains many photos
    when I tried it in my
    > Dreamweaver, so you should select the whole image by the
    mouse. At the
    > bottom
    > of Dreamweaver, you will find properties window at the
    bottom.
    > You will find Align optin, choose Center from options
    beside it.
    > Another way, you can do it through HTML.
    > Using Dreamweaver, look at the code by selecting
    clicking on Code on the
    > left
    > up corner in Dreamweaver. If you wrote this page, you
    will find HTML table
    > tags.
    > If you did not, look for this:
    > <table width="901" height="601" border="0"
    cellpadding="0" cellspacing="0"
    > id="Tableau_01"> in your code.
    > Inside this tage add Align="center", so it should look
    like this:
    > <table width="901" height="601" border="0"
    cellpadding="0" cellspacing="0"
    > id="Tableau_01" align="center">
    >
    > I hope my answer is helpful!
    >

  • How to stop itunes quitting in the middle of playback

    Hi everyone. Does anyone know how to set my iTunes or Mac up so that iTunes won't quit in the middle of playback? I'm streaming to my TV using Apple TV, and after a while, my screen goes blank and when I go back to my computer to check, I find that iTunes has logged out or quit. I've already set my energy saving preferences to 'never sleep' but this still happens and there is no iTunes preference to prevent it from happening. Any help would be most helpful. Thank you!

    Pages version? Number, please!

  • How to print a picture in the middle of the paper.

    我想把图片打印到纸的中间即上下左右均居中。但是每次打印都是在左上角。

    Can you work out what the actual HTML is to do
    "Whatever it was that you wanted to do" ? { I couldn't understand that }
    I.e If you make up a Test table, with Your Text editor can you get a sample output that looks like you want?
    But the problem is i am able to change the background of the full cell. But i don't need to change the background of the full cell always. For example if Nextti value is 15/1/2005 & Duration is 30 then the shade should start from the middle of January Cell (because of the date 15th)end in the middle of next cell (February). If the duration is 15 then it should end in the (January) same end of cell.
    Is this something that can be done in HTML?
    If your question is 'amenable' to HTML, figure out conditions for which you want to Set a certain color....
    If the color in one cell for instance depends on the Next Cell, then you're going to have to buffer the whole Table ROW....
    Set which ones should be RED for instance, then output that ROW in HTML...
    If you are using Java for this, then also be aware that you might need to escape certain characters like use "\\" to get "\"
    You'd also probaly have an easier time, however you are doing this if you used some sort of CSS .......

  • How to align flash content to the middle of the screen in browser?

    I am currently building a website in flash cs5.5 using AS2.0. One of the pages is 1024px wide by 1536 height. I want the screen to show only the first half of the screen and then the user has to scroll down using the browser scrollbar to see the second half of the screen.
    Below is the html code. I have changed the 'overflow' from hidden to auto so that the website is scrollable. However when i preview the website in the browser, it is aligned to the left. Even though below (highlighted in red) it says 'middle'. This is not what i want, i want the website to me aligned in the middle so that there is a border on either side of the website.I have tried numerous things to fix it but all to no avail. Could someone please help. Let me know if you need anymore info.
    Thanks
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
      <title>aboutus</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <style type="text/css" media="screen">
      html, body { height:100%; background-color: #333333;}
      body { margin:0; padding:0; overflow:auto; }
      #flashContent { width:100%; height:100%; }
      </style>
    </head>
    <body>
      <div id="flashContent">
       <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="1024" height="1536" id="aboutus" align="middle">
        <param name="movie" value="aboutus.swf" />
        <param name="quality" value="best" />
        <param name="bgcolor" value="#333333" />
        <param name="play" value="true" />
        <param name="loop" value="true" />
        <param name="wmode" value="window" />
        <param name="scale" value="showall" />
        <param name="menu" value="true" />
        <param name="devicefont" value="false" />
        <param name="salign" value="" />
        <param name="allowScriptAccess" value="sameDomain" />
        <!--[if !IE]>-->
        <object type="application/x-shockwave-flash" data="aboutus.swf" width="1024" height="1536">
         <param name="movie" value="aboutus.swf" />
         <param name="quality" value="best" />
         <param name="bgcolor" value="#333333" />
         <param name="play" value="true" />
         <param name="loop" value="true" />
         <param name="wmode" value="window" />
         <param name="scale" value="showall" />
         <param name="menu" value="true" />
         <param name="devicefont" value="false" />
         <param name="salign" value="" />
         <param name="allowScriptAccess" value="sameDomain" />
        <!--<![endif]-->
         <a href="http://www.adobe.com/go/getflash">
          <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
         </a>
        <!--[if !IE]>-->
        </object>
        <!--<![endif]-->
       </object>
      </div>
    </body>
    </html>

    #flashContent {    
    width: 1024px;
    margin-left: auto;
    margin-right: auto;
    Get rid of the 100% w/h and give flashContent a set width (1024).
    Then you can give the right and left an auto margin... centering the <div id="flashContent">.
    Best wishes,
    Adninjastrator

  • How to attach a file fin the middle tier in the workflow notification

    My requirement
    1) File is there in the middle tier (file name : invoice_99.pdf )
    2) From workflow notification I need to read that file (invoice_99.pdf) and
    open it from the notification when user click on it
    can you please let me know is there any way to handle this

    Thiru,
    This is not the right forum for this.
    Btw, I have done exactly same requirement several times and it's easy to do.
    1)Create a Document Attribute and specify to attach it to the notif msg.
    2)Create a PL/SQL function activity in workflow
    3)In the PL/SQL proc, Load the file using dbms_lob into a LOB and set the attribute using
    wf_engine.SetItemAttrText(itemtype      => itemType
    ,itemkey      => itemkey
    ,aname      => 'SRQ_REPORT'
    ,avalue           => 'PLSQLCLOB:xxx_gbl_wf.get_pdf_quote/'||v_report_request_id||':'||v_qot_number);
    Hope this helps
    Srini

Maybe you are looking for

  • Java Script Errors

    All the sudden lately in my Contribute 3 I have been getting these weird error messages. First of all when I open Contriubte now it does not go to my index page like it used to. It now goes to this address "about:startpage". I can select the index or

  • Get currently opened file in code editor

    Hi, I am writing an extension for Oracle Jdeveloper. I have created a view and now I need to access the currently opened file in the code editor. However, all I get is the context of my own view: Context.newIdeContext(this); But how can I get the Cod

  • Ability to link manpower availability

    Hi, In SAP PP, is there any possibility to link HR Database for leave / absence with production scheduling?? Moreover In SAP PP, how can we assign manpower while scheduling production orders? Regards

  • Safari 4.0.3 causes loss of AirPort conection

    Opening Safari 4.0.3, particularly from sleep, frequently results in loss of AirPort connection. I then need to manually reconnect. Any recommendations?

  • ODS BEx Indicator flag

    How can I check what ODS have the BEx Indicator flag checked? Thanks